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

模拟服务器

开发平台:

C/C++

  1. }
  2. else
  3. {
  4. sDecision.m_btDecision = 3;
  5. }
  6. if (g_pClient)
  7. g_pClient->SendPackToServer(&sDecision, sizeof(TRADE_DECISION_COMMAND));
  8. }
  9. #endif
  10. #ifndef _SERVER
  11. //-------------------------------------------------------------------------
  12. // 功能:收到服务器通知有人申请加入队伍
  13. //-------------------------------------------------------------------------
  14. void KPlayer::s2cApplyAddTeam(BYTE* pProtocol)
  15. {
  16. // 状态检查 (还需要检查 npc 的队伍开放状态 not end)
  17. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  18. {
  19. ApplySelfTeamInfo();
  20. return;
  21. }
  22. // 寻找 npc
  23. PLAYER_APPLY_ADD_TEAM *pAddTeam = (PLAYER_APPLY_ADD_TEAM*)pProtocol;
  24. int nNpcNo = NpcSet.SearchID(pAddTeam->m_dwTarNpcID);
  25. if (nNpcNo == 0)
  26. return;
  27. int i, nFreeListNo;
  28. // 如果已经存在,更新
  29. for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
  30. {
  31. if (m_cTeam.m_sApplyList[i].m_dwNpcID == pAddTeam->m_dwTarNpcID)
  32. {
  33. m_cTeam.m_sApplyList[i].m_nLevel = Npc[nNpcNo].m_Level;
  34. m_cTeam.m_sApplyList[i].m_dwTimer = MAX_APPLY_TEAM_TIME;
  35. strcpy(m_cTeam.m_sApplyList[i].m_szName, Npc[nNpcNo].Name);
  36. m_cTeam.UpdateInterface();
  37. return;
  38. }
  39. }
  40. // 寻找申请人list空位
  41. for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
  42. {
  43. if (m_cTeam.m_sApplyList[i].m_dwNpcID == 0)
  44. {
  45. nFreeListNo = i;
  46. break;
  47. }
  48. }
  49. if (i >= MAX_TEAM_APPLY_LIST) // 没找到申请人空位
  50. return;
  51. m_cTeam.m_sApplyList[nFreeListNo].m_dwNpcID = pAddTeam->m_dwTarNpcID;
  52. m_cTeam.m_sApplyList[nFreeListNo].m_nLevel = Npc[nNpcNo].m_Level;
  53. m_cTeam.m_sApplyList[nFreeListNo].m_dwTimer = MAX_APPLY_TEAM_TIME;
  54. strcpy(m_cTeam.m_sApplyList[nFreeListNo].m_szName, Npc[nNpcNo].Name);
  55. m_cTeam.UpdateInterface();
  56. KSystemMessage sMsg;
  57. sprintf(sMsg.szMessage, MSG_TEAM_APPLY_ADD, Npc[nNpcNo].Name);
  58. sMsg.eType = SMT_TEAM;
  59. sMsg.byConfirmType = SMCT_UI_TEAM_APPLY;
  60. sMsg.byPriority = 3;
  61. sMsg.byParamSize = sizeof(KUiPlayerItem);
  62. KUiPlayerItem player;
  63. strcpy(player.Name, Npc[nNpcNo].Name);
  64. player.nIndex = 0;
  65. player.uId = pAddTeam->m_dwTarNpcID;
  66. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&player);
  67. return;
  68. }
  69. #endif
  70. #ifdef _SERVER
  71. //-------------------------------------------------------------------------
  72. // 功能:加入门派
  73. //-------------------------------------------------------------------------
  74. BOOL KPlayer::AddFaction(char *lpszFactionName)
  75. {
  76. if ( !m_cFaction.AddFaction(Npc[m_nIndex].m_Series, lpszFactionName) )
  77. return FALSE;
  78. // 改变阵营
  79. Npc[m_nIndex].SetCamp(m_cFaction.GetGurFactionCamp());
  80. // 给客户端发消息
  81. SendFactionData();
  82. return TRUE;
  83. }
  84. #endif
  85. #ifdef _SERVER
  86. //-------------------------------------------------------------------------
  87. // 功能:加入门派
  88. //-------------------------------------------------------------------------
  89. BOOL KPlayer::AddFaction(int nFactionID)
  90. {
  91. if ( !m_cFaction.AddFaction(Npc[m_nIndex].m_Series, nFactionID) )
  92. return FALSE;
  93. // 改变阵营
  94. Npc[m_nIndex].SetCamp(m_cFaction.GetGurFactionCamp());
  95. // 给客户端发消息
  96. SendFactionData();
  97. return TRUE;
  98. }
  99. #endif
  100. #ifdef _SERVER
  101. //-------------------------------------------------------------------------
  102. // 功能:离开门派
  103. //-------------------------------------------------------------------------
  104. BOOL KPlayer::LeaveCurFaction()
  105. {
  106. m_cFaction.LeaveFaction();
  107. // 改变阵营
  108. Npc[m_nIndex].SetCamp(camp_free);
  109. // 给客户端发消息
  110. PLAYER_LEAVE_FACTION sLeave;
  111. sLeave.ProtocolType = s2c_playerleavefaction;
  112. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeave, sizeof(PLAYER_LEAVE_FACTION));
  113. return TRUE;
  114. }
  115. #endif
  116. #ifdef _SERVER
  117. //-------------------------------------------------------------------------
  118. // 功能:开放当前门派某个等级的技能
  119. //-------------------------------------------------------------------------
  120. BOOL KPlayer::CurFactionOpenSkill(int nLevel)
  121. {
  122. if ( !m_cFaction.OpenCurSkillLevel(nLevel, &Npc[m_nIndex].m_SkillList) )
  123. return FALSE;
  124. PLAYER_FACTION_SKILL_LEVEL sLevel;
  125. sLevel.ProtocolType = s2c_playerfactionskilllevel;
  126. sLevel.m_btCurFactionID = m_cFaction.m_nCurFaction;
  127. sLevel.m_btLevel = nLevel;
  128. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLevel, sizeof(PLAYER_FACTION_SKILL_LEVEL));
  129. return TRUE;
  130. }
  131. #endif
  132. #ifdef _SERVER
  133. //-------------------------------------------------------------------------
  134. // 功能:清空任务临时变量
  135. //-------------------------------------------------------------------------
  136. void KPlayer::TaskClearTempVal()
  137. {
  138. this->m_cTask.ClearTempVar();
  139. }
  140. #endif
  141. #ifdef _SERVER
  142. //-------------------------------------------------------------------------
  143. // 功能:得到任务完成情况
  144. //-------------------------------------------------------------------------
  145. int KPlayer::TaskGetSaveVal(int nNo)
  146. {
  147. return this->m_cTask.GetSaveVal(nNo);
  148. }
  149. #endif
  150. #ifdef _SERVER
  151. //-------------------------------------------------------------------------
  152. // 功能:设定任务完成情况
  153. //-------------------------------------------------------------------------
  154. void KPlayer::TaskSetSaveVal(int nNo, BOOL bFlag)
  155. {
  156. this->m_cTask.SetSaveVal(nNo, bFlag);
  157. }
  158. #endif
  159. #ifdef _SERVER
  160. //-------------------------------------------------------------------------
  161. // 功能:得到任务临时过程控制变量值
  162. //-------------------------------------------------------------------------
  163. int KPlayer::TaskGetClearVal(int nNo)
  164. {
  165. return this->m_cTask.GetClearVal(nNo);
  166. }
  167. #endif
  168. #ifdef _SERVER
  169. //-------------------------------------------------------------------------
  170. // 功能:设定任务临时过程控制变量值
  171. //-------------------------------------------------------------------------
  172. void KPlayer::TaskSetClearVal(int nNo, int nVal)
  173. {
  174. this->m_cTask.SetClearVal(nNo, nVal);
  175. }
  176. #endif
  177. #ifndef _SERVER
  178. void KPlayer::SetDefaultImmedSkill()
  179. {
  180. //获取玩家左右键技能为默认物理技能
  181. int nDetailType = Player[CLIENT_PLAYER_INDEX].m_ItemList.GetWeaponType();
  182. int nParticularType = Player[CLIENT_PLAYER_INDEX].m_ItemList.GetWeaponParticular();
  183. //近身武器
  184. if (nDetailType == 0)
  185. {
  186. Player[CLIENT_PLAYER_INDEX].SetLeftSkill(g_nMeleeWeaponSkill[nParticularType]);
  187. Player[CLIENT_PLAYER_INDEX].SetRightSkill(g_nMeleeWeaponSkill[nParticularType]);
  188. }//远程武器
  189. else if (nDetailType == 1)
  190. {
  191. Player[CLIENT_PLAYER_INDEX].SetLeftSkill(g_nRangeWeaponSkill[nParticularType]);
  192. Player[CLIENT_PLAYER_INDEX].SetRightSkill(g_nRangeWeaponSkill[nParticularType]);
  193. }//空手
  194. else if (nDetailType == -1)
  195. {
  196. Player[CLIENT_PLAYER_INDEX].SetLeftSkill(g_nHandSkill);
  197. Player[CLIENT_PLAYER_INDEX].SetRightSkill(g_nHandSkill);
  198. }
  199. }
  200. void KPlayer::SetLeftSkill(int nSkillID)
  201. {
  202. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.GetCurrentLevel(nSkillID) <= 0) return;
  203. m_nLeftSkillID = nSkillID;
  204. KUiGameObject Info;
  205. Info.uGenre = CGOG_SKILL_SHORTCUT;
  206. Info.uId = m_nLeftSkillID;
  207. CoreDataChanged(GDCNI_PLAYER_IMMED_ITEMSKILL, (unsigned int)&Info, -1);
  208. }
  209. void KPlayer::SetRightSkill(int nSkillID)
  210. {
  211. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.GetCurrentLevel(nSkillID) <= 0) return;
  212. m_nRightSkillID = nSkillID;
  213. // 检查是否是光环技能
  214. ISkill * pOrdinSkill = g_SkillManager.GetSkill(nSkillID, 1);
  215. if (!pOrdinSkill) 
  216.         return;
  217. if (pOrdinSkill->IsAura())
  218. {
  219. Npc[m_nIndex].SetAuraSkill(nSkillID);
  220. }
  221. else
  222. {
  223. Npc[m_nIndex].SetAuraSkill(0);
  224. }
  225. KUiGameObject Info;
  226. Info.uGenre = CGOG_SKILL_SHORTCUT;
  227. Info.uId = m_nRightSkillID;
  228. CoreDataChanged(GDCNI_PLAYER_IMMED_ITEMSKILL, (unsigned int)&Info, -2);
  229. }
  230. void KPlayer::UpdateWeaponSkill()
  231. {
  232. if (m_nLeftSkillID > 0)
  233. {
  234. ISkill * pISkill = g_SkillManager.GetSkill(m_nLeftSkillID, 1);
  235. if (!pISkill) 
  236.             return;
  237. if (pISkill->IsPhysical())
  238. {
  239. SetLeftSkill(Npc[m_nIndex].GetCurActiveWeaponSkill());
  240. }
  241. }
  242. if (m_nRightSkillID > 0)
  243. {
  244. ISkill * pISkill = (KSkill *) g_SkillManager.GetSkill(m_nRightSkillID, 1);
  245. if (!pISkill) 
  246.             return;
  247. if (pISkill->IsPhysical())
  248. {
  249. SetRightSkill(Npc[m_nIndex].GetCurActiveWeaponSkill());
  250. }
  251. }
  252. }
  253. #endif
  254. #ifndef _SERVER
  255. //-------------------------------------------------------------------------
  256. // 功能:设定当前聊天频道
  257. //-------------------------------------------------------------------------
  258. void KPlayer::SetChatCurChannel(int nChannelNo)
  259. {
  260. m_cChat.SetCurChannel(nChannelNo);
  261. }
  262. #endif
  263. #ifndef _SERVER
  264. //-------------------------------------------------------------------------
  265. // 功能:邀请加入队伍
  266. //-------------------------------------------------------------------------
  267. void KPlayer::TeamInviteAdd(DWORD dwNpcID)
  268. {
  269. m_cTeam.InviteAdd(dwNpcID);
  270. }
  271. #endif
  272. #ifdef _SERVER
  273. //-------------------------------------------------------------------------
  274. // 功能:收到客户端发来的聊天语句
  275. //-------------------------------------------------------------------------
  276. void KPlayer::ServerSendChat(BYTE* pProtocol)
  277. {
  278. m_cChat.ServerSendChat(m_nPlayerIndex, pProtocol);
  279. }
  280. #endif
  281. #ifdef _SERVER
  282. //-------------------------------------------------------------------------
  283. // 功能:收到客户端要求增加基本属性点(0=Strength 1=Dexterity 2=Vitality 3=Engergy)
  284. //-------------------------------------------------------------------------
  285. void KPlayer::AddBaseAttribute(BYTE* pProtocol)
  286. {
  287. PLAYER_ADD_BASE_ATTRIBUTE_COMMAND *pAdd = (PLAYER_ADD_BASE_ATTRIBUTE_COMMAND*)pProtocol;
  288. switch (pAdd->m_btAttribute)
  289. {
  290. case ATTRIBUTE_STRENGTH:
  291. AddBaseStrength(pAdd->m_nAddNo);
  292. break;
  293. case ATTRIBUTE_DEXTERITY:
  294. AddBaseDexterity(pAdd->m_nAddNo);
  295. break;
  296. case ATTRIBUTE_VITALITY:
  297. AddBaseVitality(pAdd->m_nAddNo);
  298. break;
  299. case ATTRIBUTE_ENGERGY:
  300. AddBaseEngergy(pAdd->m_nAddNo);
  301. break;
  302. }
  303. }
  304. #endif
  305. #define MAX_ORDINSKILL_LEVEL_ALWAYS  20//不包括其它情况对技能等级的变动之外的,一般最大技能等级
  306. #ifdef _SERVER
  307. //-------------------------------------------------------------------------
  308. // 功能:收到客户端要求增加某个技能的点数
  309. //-------------------------------------------------------------------------
  310. void KPlayer::AddSkillPoint(BYTE* pProtocol)
  311. {
  312. PLAYER_ADD_SKILL_POINT_COMMAND *pAdd = (PLAYER_ADD_SKILL_POINT_COMMAND*)pProtocol;
  313. int nSkillIndex, nSkillLevel;
  314. nSkillIndex = Npc[m_nIndex].m_SkillList.FindSame(pAdd->m_nSkillID);
  315. if (nSkillIndex == 0)
  316. return;
  317. nSkillLevel = Npc[m_nIndex].m_SkillList.GetSkillIdxLevel(nSkillIndex);
  318. if (m_nSkillPoint >= pAdd->m_nAddPoint && nSkillIndex )//&& nSkillLevel + pAdd->m_nAddPoint <= MAX_SKILLLEVEL
  319. {
  320. ISkill * pSkill = NULL;
  321. if (nSkillLevel == 0)
  322. {
  323. pSkill =  g_SkillManager.GetSkill(pAdd->m_nSkillID, 1);
  324. }
  325. else
  326. {
  327. pSkill =  g_SkillManager.GetSkill(pAdd->m_nSkillID, nSkillLevel);
  328. }
  329. if (pSkill)
  330. {
  331. //有对应的技能升级脚本,优先执行脚本
  332. if (pSkill->GetSkillLevelUpScriptId())
  333. {
  334. ExecuteScript(pSkill->GetSkillLevelUpScriptId(), "main", pAdd->m_nAddPoint);
  335. nSkillLevel = Npc[m_nIndex].m_SkillList.GetSkillIdxLevel(nSkillIndex);
  336. }
  337. else
  338. {
  339. /*
  340. 技能升级的常规
  341. 1。所有能够加点的技能,最高只能加到20级。
  342. 2。假设一个玩家的等级是x,一个技能的基本学习等级是y,那么他能够学习这个技能的最高等级是x-y。
  343. 3。使用技能需要加入一些情况的判断,第一,是否是骑马状态;第二,他装备的武器的详细类别是否为指定数值,-1表示没有需求。
  344. */
  345. switch(pSkill->GetSkillStyle())
  346. {
  347. case SKILL_SS_Missles: // 子弹类 本技能用于发送子弹类
  348. case SKILL_SS_Melee:
  349. case SKILL_SS_InitiativeNpcState: // 主动类 本技能用于改变当前Npc的主动状态
  350. case SKILL_SS_PassivityNpcState: // 被动类 本技能用于改变Npc的被动状态
  351. {
  352. int nWantToBeLevel = nSkillLevel + pAdd->m_nAddPoint;
  353. //Limit2
  354. if (nWantToBeLevel <= g_SkillManager.GetSkillMaxLevel(pAdd->m_nSkillID) && nWantToBeLevel <= Npc[m_nIndex].m_Level - ((KSkill*)pSkill)->GetSkillReqLevel() + 1)
  355. {
  356. if ( !Npc[m_nIndex].m_SkillList.IncreaseLevel(nSkillIndex, pAdd->m_nAddPoint) )
  357. return;
  358. m_nSkillPoint -= pAdd->m_nAddPoint;
  359. nSkillLevel += pAdd->m_nAddPoint;
  360. }
  361. else
  362. {
  363. if (nWantToBeLevel >=  g_SkillManager.GetSkillMaxLevel(pAdd->m_nSkillID))
  364. {
  365. char szMsg[100];
  366. sprintf(szMsg, "您的%s技能等级已经达到极限,不能再升级了。", pSkill->GetSkillName());
  367. KPlayerChat::SendSystemInfo(1, m_nPlayerIndex, "技能升级消息", (char *) szMsg, strlen(szMsg) );
  368. }
  369. else 
  370. {
  371. char szMsg[100];
  372. sprintf(szMsg, "您的战斗技能必须达到%d级才能升级%s技能。", ((KSkill *)pSkill)->GetSkillReqLevel() -1 +  pAdd->m_nAddPoint + nSkillLevel,  ((KSkill*)pSkill)->GetSkillName());
  373. KPlayerChat::SendSystemInfo(1, m_nPlayerIndex, "技能升级消息", (char *) szMsg, strlen(szMsg) );
  374. }
  375. }
  376. }
  377. break;
  378. case SKILL_SS_Thief:
  379. {
  380. return;
  381. }break;
  382. }
  383. }
  384. // 把当前此技能的点数和剩余技能点发给客户端
  385. PLAYER_SKILL_LEVEL_SYNC sSkill;
  386. sSkill.ProtocolType = s2c_playerskilllevel;
  387. sSkill.m_nSkillID = pAdd->m_nSkillID;
  388. sSkill.m_nSkillLevel = nSkillLevel;
  389. sSkill.m_nLeavePoint = m_nSkillPoint;
  390. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSkill, sizeof(PLAYER_SKILL_LEVEL_SYNC));
  391. }
  392. }
  393. }
  394. #endif
  395. #ifdef _SERVER
  396. //-------------------------------------------------------------------------
  397. // 功能:服务器端拣物品
  398. //-------------------------------------------------------------------------
  399. BOOL KPlayer::ServerPickUpItem(BYTE* pProtocol)
  400. {
  401. PLAYER_PICKUP_ITEM_COMMAND *pPickUp = (PLAYER_PICKUP_ITEM_COMMAND*)pProtocol;
  402. int nObjIndex, nNpcX, nNpcY, nObjX, nObjY;
  403. nObjIndex = ObjSet.FindID(pPickUp->m_nObjID);
  404. if (nObjIndex == 0)
  405. return FALSE;
  406. if (Object[nObjIndex].m_nBelong != -1)
  407. {
  408. if (!m_cTeam.m_nFlag)
  409. {
  410. if (Object[nObjIndex].m_nBelong != m_nPlayerIndex)
  411. {
  412. SHOW_MSG_SYNC sMsg;
  413. sMsg.ProtocolType = s2c_msgshow;
  414. if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
  415. sMsg.m_wMsgID = enumMSG_ID_MONEY_CANNOT_PICKUP;
  416. else
  417. sMsg.m_wMsgID = enumMSG_ID_OBJ_CANNOT_PICKUP;
  418. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  419. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  420. return FALSE;
  421. }
  422. }
  423. else
  424. {
  425. if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
  426. {
  427. if (Object[nObjIndex].m_nBelong != m_nPlayerIndex &&
  428. !g_Team[m_cTeam.m_nID].CheckIn(Object[nObjIndex].m_nBelong))
  429. {
  430. SHOW_MSG_SYNC sMsg;
  431. sMsg.ProtocolType = s2c_msgshow;
  432. sMsg.m_wMsgID = enumMSG_ID_MONEY_CANNOT_PICKUP;
  433. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  434. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  435. return FALSE;
  436. }
  437. }
  438. else if (Object[nObjIndex].m_nKind == Obj_Kind_Item)
  439. {
  440. if (Object[nObjIndex].m_nItemDataID <= 0 || Object[nObjIndex].m_nItemDataID >= MAX_ITEM)
  441. {
  442. _ASSERT(0);
  443. return FALSE;
  444. }
  445. if ((Item[Object[nObjIndex].m_nItemDataID].GetGenre() == item_task && Object[nObjIndex].m_nBelong != m_nPlayerIndex) ||
  446. !g_Team[m_cTeam.m_nID].CheckIn(Object[nObjIndex].m_nBelong))
  447. {
  448. SHOW_MSG_SYNC sMsg;
  449. sMsg.ProtocolType = s2c_msgshow;
  450. sMsg.m_wMsgID = enumMSG_ID_OBJ_CANNOT_PICKUP;
  451. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  452. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  453. return FALSE;
  454. }
  455. }
  456. else
  457. {
  458. return FALSE;
  459. }
  460. }
  461. }
  462. // 判断距离
  463. if (Object[nObjIndex].m_nSubWorldID != Npc[m_nIndex].m_SubWorldIndex)
  464. return FALSE;
  465. SubWorld[Object[nObjIndex].m_nSubWorldID].Map2Mps(
  466. Object[nObjIndex].m_nRegionIdx,
  467. Object[nObjIndex].m_nMapX,
  468. Object[nObjIndex].m_nMapY,
  469. Object[nObjIndex].m_nOffX,
  470. Object[nObjIndex].m_nOffY,
  471. &nObjX,
  472. &nObjY);
  473. SubWorld[Npc[m_nIndex].m_SubWorldIndex].Map2Mps(
  474. Npc[m_nIndex].m_RegionIndex,
  475. Npc[m_nIndex].m_MapX,
  476. Npc[m_nIndex].m_MapY,
  477. Npc[m_nIndex].m_OffX,
  478. Npc[m_nIndex].m_OffY,
  479. &nNpcX,
  480. &nNpcY);
  481. if ( PLAYER_PICKUP_SERVER_DISTANCE < (nNpcX - nObjX) * (nNpcX - nObjX) + (nNpcY - nObjY) * (nNpcY - nObjY))
  482. {
  483. SHOW_MSG_SYNC sMsg;
  484. sMsg.ProtocolType = s2c_msgshow;
  485. sMsg.m_wMsgID = enumMSG_ID_OBJ_TOO_FAR;
  486. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  487. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  488. return FALSE;
  489. }
  490. switch (Object[nObjIndex].m_nKind)
  491. {
  492. case Obj_Kind_Item: // 掉在地上的装备
  493. {
  494. int nItemIdx = m_ItemList.Add(Object[nObjIndex].m_nItemDataID, pPickUp->m_btPosType, pPickUp->m_btPosX, pPickUp->m_btPosY);
  495. if (nItemIdx <= 0 || nItemIdx >= MAX_PLAYER_ITEM)
  496. return FALSE;
  497. if (Object[nObjIndex].m_nItemDataID <= 0 || Object[nObjIndex].m_nItemDataID >= MAX_ITEM)
  498. return FALSE;
  499. // 给客户端发送获得装备的消息
  500. SHOW_MSG_SYNC sMsg;
  501. sMsg.ProtocolType = s2c_msgshow;
  502. sMsg.m_wMsgID = enumMSG_ID_GET_ITEM;
  503. sMsg.m_lpBuf = (LPVOID)Item[Object[nObjIndex].m_nItemDataID].GetID();
  504. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  505. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  506. sMsg.m_lpBuf = 0;
  507. // 去掉Object[nObjIndex]与道具的关联。避免ItemSet的Remove被Object的Remove调用
  508. Object[nObjIndex].m_nItemDataID = 0;
  509. Object[nObjIndex].m_nItemWidth = 0;
  510. Object[nObjIndex].m_nItemHeight = 0;
  511. Object[nObjIndex].Remove(FALSE);
  512. }
  513. break;
  514. case Obj_Kind_Money: // 掉在地上的钱
  515. if ( !Earn(Object[nObjIndex].m_nMoneyNum) )
  516. return FALSE;
  517. Object[nObjIndex].SyncRemove(TRUE);
  518. if (Object[nObjIndex].m_nRegionIdx >= 0)
  519. SubWorld[Object[nObjIndex].m_nSubWorldID].m_Region[Object[nObjIndex].m_nRegionIdx].RemoveObj(nObjIndex);
  520. ObjSet.Remove(nObjIndex);
  521. break;
  522. }
  523. return TRUE;
  524. }
  525. #endif
  526. #ifdef _SERVER
  527. //-------------------------------------------------------------------------
  528. // 功能:收到客户端要求使用某个物品(鼠标右键点击)
  529. //-------------------------------------------------------------------------
  530. void KPlayer::EatItem(BYTE* pProtocol)
  531. {
  532. PLAYER_EAT_ITEM_COMMAND *pEat = (PLAYER_EAT_ITEM_COMMAND*)pProtocol;
  533. m_ItemList.EatMecidine(pEat->m_btPlace, pEat->m_btX, pEat->m_btY);
  534. }
  535. #endif
  536. #ifdef _SERVER
  537. //-------------------------------------------------------------------------
  538. // 功能:收到客户端要求使用某个物品(鼠标右键点击)
  539. //-------------------------------------------------------------------------
  540. //void KPlayer::UseItem(BYTE* pProtocol)
  541. //{
  542. // PLAYER_USE_ITEM_COMMAND *pItem = (PLAYER_USE_ITEM_COMMAND*)pProtocol;
  543. //}
  544. #endif
  545. #ifdef _SERVER
  546. void KPlayer::ServerMoveItem(BYTE* pProtocol)
  547. {
  548. PLAYER_MOVE_ITEM_COMMAND *pMove = (PLAYER_MOVE_ITEM_COMMAND*)pProtocol;
  549. ItemPos DownPos, UpPos;
  550. DownPos.nPlace = pMove->m_btDownPos;
  551. DownPos.nX = pMove->m_btDownX;
  552. DownPos.nY = pMove->m_btDownY;
  553. UpPos.nPlace = pMove->m_btUpPos;
  554. UpPos.nX = pMove->m_btUpX;
  555. UpPos.nY = pMove->m_btUpY;
  556. //EXCHANGE_ITEM_RESPONE eir;
  557. //eir.ProtocolType = s2c_exchangerespone;
  558. if (this->CheckTrading() && DownPos.nPlace == pos_traderoom)
  559. {
  560. if (this->m_cTrade.m_nTradeLock)
  561. return;
  562. }
  563. m_ItemList.ExchangeItem(&DownPos, &UpPos);
  564. BYTE byFinished = s2c_itemexchangefinish;
  565. if (g_pServer)
  566. g_pServer->PackDataToClient(m_nNetConnectIdx, &byFinished, sizeof(BYTE));
  567. }
  568. #endif
  569. #ifdef _SERVER
  570. void KPlayer::ServerThrowAwayItem(BYTE* pProtocol)
  571. {
  572. PLAYER_THROW_AWAY_ITEM_COMMAND *pThrow = (PLAYER_THROW_AWAY_ITEM_COMMAND*)pProtocol;
  573. KMapPos sMapPos;
  574. if ( !this->m_ItemList.Hand() )
  575. return;
  576. int nItemIdx = m_ItemList.m_Hand;
  577. GetAboutPos(&sMapPos);
  578. if (m_ItemList.Remove(nItemIdx))
  579. {
  580. int nObj;
  581. KObjItemInfo sInfo;
  582. sInfo.m_nItemID = nItemIdx;
  583. sInfo.m_nItemWidth = Item[nItemIdx].GetWidth();
  584. sInfo.m_nItemHeight = Item[nItemIdx].GetHeight();
  585. sInfo.m_nMoneyNum = 0;
  586. strcpy(sInfo.m_szName, Item[nItemIdx].m_CommonAttrib.szItemName);
  587. sInfo.m_nColorID = 0;
  588. sInfo.m_nMovieFlag = 1;
  589. sInfo.m_nSoundFlag = 1;
  590. nObj = ObjSet.Add(Item[nItemIdx].GetObjIdx(), sMapPos, sInfo);
  591. if (nObj >= 0)
  592. {
  593. if (Item[nItemIdx].GetGenre() == item_task)
  594. {
  595. Object[nObj].SetEntireBelong(this->m_nPlayerIndex);
  596. }
  597. else
  598. {
  599. Object[nObj].SetItemBelong(-1);
  600. }
  601. }
  602. }
  603. }
  604. #endif
  605. #ifdef _SERVER
  606. //-------------------------------------------------------------------------
  607. // 功能:收到客户端消息设定聊天订阅频道
  608. //-------------------------------------------------------------------------
  609. void KPlayer::ChatSetTakeChannel(BYTE* pProtocol)
  610. {
  611. CHAT_SET_CHANNEL_COMMAND *pChannel = (CHAT_SET_CHANNEL_COMMAND*)pProtocol;
  612. this->m_cChat.SetTakeChannel(pChannel->m_dwTakeChannel);
  613. }
  614. #endif
  615. #ifdef _SERVER
  616. //-------------------------------------------------------------------------
  617. // 功能:收到客户端请求转发聊天添加好友信息
  618. //-------------------------------------------------------------------------
  619. void KPlayer::ChatTransmitApplyAddFriend(BYTE* pProtocol)
  620. {
  621. CHAT_APPLY_ADD_FRIEND_COMMAND *pAdd = (CHAT_APPLY_ADD_FRIEND_COMMAND*)pProtocol;
  622. int nPlayerIdx = FindAroundPlayer(pAdd->m_dwTargetNpcID);
  623. if (nPlayerIdx < 0)
  624. return;
  625. m_cChat.m_nAddFriendList[m_cChat.m_nListPos++] = nPlayerIdx;
  626. m_cChat.m_nListPos %= CHAT_APPLY_ADD_FRIEND_LIST;
  627. CHAT_APPLY_ADD_FRIEND_SYNC sAdd;
  628. sAdd.ProtocolType = s2c_chatapplyaddfriend;
  629. sAdd.m_nSrcPlayerIdx = m_nPlayerIndex;
  630. strcpy(sAdd.m_szSourceName, Npc[m_nIndex].Name);
  631. memset(sAdd.m_szInfo, 0, sizeof(sAdd.m_szInfo));
  632. memcpy(sAdd.m_szInfo, pAdd->m_szInfo, pAdd->m_wLength + 1 + sizeof(pAdd->m_szInfo) - sizeof(CHAT_APPLY_ADD_FRIEND_COMMAND));
  633. g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sAdd, sizeof(CHAT_APPLY_ADD_FRIEND_SYNC));
  634. }
  635. #endif
  636. #ifdef _SERVER
  637. //-------------------------------------------------------------------------
  638. // 功能:收到客户端消息添加聊天好友
  639. //-------------------------------------------------------------------------
  640. BOOL KPlayer::ChatAddFriend(BYTE* pProtocol)
  641. {
  642. CHAT_ADD_FRIEND_COMMAND *pAdd = (CHAT_ADD_FRIEND_COMMAND*)pProtocol;
  643. if (pAdd->m_nTargetPlayerIdx < 0 || pAdd->m_nTargetPlayerIdx >= MAX_PLAYER)
  644. goto AddFalse;
  645. if ( !Player[pAdd->m_nTargetPlayerIdx].m_nIndex )
  646. goto AddFalse;
  647. int i;
  648. for (i = 0; i < CHAT_APPLY_ADD_FRIEND_LIST; i++)
  649. {
  650. if (m_nPlayerIndex == Player[pAdd->m_nTargetPlayerIdx].m_cChat.m_nAddFriendList[i])
  651. break;
  652. }
  653. if (i >= CHAT_APPLY_ADD_FRIEND_LIST)
  654. goto AddFalse;
  655. m_cChat.AddFriendData(m_nPlayerIndex, pAdd->m_nTargetPlayerIdx);
  656. Player[pAdd->m_nTargetPlayerIdx].m_cChat.AddFriendData(pAdd->m_nTargetPlayerIdx, m_nPlayerIndex);
  657. return TRUE;
  658. AddFalse:
  659. CHAT_ADD_FRIEND_FAIL_SYNC sFail;
  660. sFail.ProtocolType = s2c_chataddfriendfail;
  661. sFail.m_nTargetPlayerIdx = pAdd->m_nTargetPlayerIdx;
  662. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sFail, sizeof(CHAT_ADD_FRIEND_FAIL_SYNC));
  663. return FALSE;
  664. }
  665. #endif
  666. #ifdef _SERVER
  667. //-------------------------------------------------------------------------
  668. // 功能:收到客户端消息拒绝添加聊天好友
  669. //-------------------------------------------------------------------------
  670. void KPlayer::ChatRefuseFriend(BYTE* pProtocol)
  671. {
  672. CHAT_REFUSE_FRIEND_COMMAND *pRefuse = (CHAT_REFUSE_FRIEND_COMMAND*)pProtocol;
  673. if (pRefuse->m_nTargetPlayerIdx < 0 || pRefuse->m_nTargetPlayerIdx >= MAX_PLAYER)
  674. return;
  675. if (Player[pRefuse->m_nTargetPlayerIdx].m_nIndex == 0)
  676. return;
  677. for (int i = 0; i < CHAT_APPLY_ADD_FRIEND_LIST; i++)
  678. {
  679. if (m_nPlayerIndex == Player[pRefuse->m_nTargetPlayerIdx].m_cChat.m_nAddFriendList[i])
  680. {
  681. CHAT_REFUSE_FRIEND_SYNC sRefuse;
  682. sRefuse.ProtocolType = s2c_chatrefusefriend;
  683. g_StrCpy(sRefuse.m_szName, Npc[m_nIndex].Name);
  684. sRefuse.m_wLength = sizeof(CHAT_REFUSE_FRIEND_SYNC) - 1 - sizeof(sRefuse.m_szName) + strlen(sRefuse.m_szName);
  685. g_pServer->PackDataToClient(Player[pRefuse->m_nTargetPlayerIdx].m_nNetConnectIdx, (BYTE*)&sRefuse, sRefuse.m_wLength + 1);
  686. return;
  687. }
  688. }
  689. }
  690. #endif
  691. #ifdef _SERVER
  692. //-------------------------------------------------------------------------
  693. // 功能:玩家登录时收到客户端请求重新发送所有聊天好友数据(带名字)
  694. //-------------------------------------------------------------------------
  695. void KPlayer::ChatResendAllFriend(BYTE* pProtocol)
  696. {
  697. if ( m_cChat.m_nSyncState != 1)
  698. return;
  699. m_cChat.m_nSyncState = 2;
  700. m_cChat.m_pStateSendPos = (CChatFriend*)m_cChat.m_cFriendTeam[0].m_cEveryOne.GetHead();
  701. if ( !m_cChat.m_pStateSendPos )
  702. m_cChat.m_nSyncState = 0;
  703. }
  704. #endif
  705. #ifdef _SERVER
  706. //-------------------------------------------------------------------------
  707. // 功能:玩家登录时收到客户端请求发送某个聊天好友数据(带名字)
  708. //-------------------------------------------------------------------------
  709. void KPlayer::ChatSendOneFriendData(BYTE* pProtocol)
  710. {
  711. CHAT_APPLY_SEND_ONE_FRIEND_NAME_COMMAND *pApply = (CHAT_APPLY_SEND_ONE_FRIEND_NAME_COMMAND*)pProtocol;
  712. m_cChat.ResendOneFriendData(pApply->m_dwID, m_nPlayerIndex);
  713. }
  714. #endif
  715. #ifdef _SERVER
  716. //-------------------------------------------------------------------------
  717. // 功能:收到客户端申请删除某个聊天好友
  718. //-------------------------------------------------------------------------
  719. void KPlayer::ChatDeleteFriend(BYTE* pProtocol)
  720. {
  721. CHAT_DELETE_FRIEND_COMMAND *pDelete = (CHAT_DELETE_FRIEND_COMMAND*)pProtocol;
  722. m_cChat.DeleteFriend(pDelete->m_dwID, m_dwID);
  723. }
  724. #endif
  725. #ifdef _SERVER
  726. //-------------------------------------------------------------------------
  727. // 功能:收到客户端申请再次删除某个聊天好友
  728. //-------------------------------------------------------------------------
  729. void KPlayer::ChatRedeleteFriend(BYTE* pProtocol)
  730. {
  731. CHAT_REDELETE_FRIEND_COMMAND *pDelete = (CHAT_REDELETE_FRIEND_COMMAND*)pProtocol;
  732. this->m_cChat.RedeleteFriend(pDelete->m_dwID, m_nPlayerIndex);
  733. }
  734. #endif
  735. #ifdef _SERVER
  736. //-------------------------------------------------------------------------
  737. // 功能:收到客户端申请进入待交易状态
  738. //-------------------------------------------------------------------------
  739. void KPlayer::TradeApplyOpen(BYTE* pProtocol)
  740. {
  741. if ( CheckTrading() )
  742. return;
  743. TRADE_APPLY_OPEN_COMMAND *pApply = (TRADE_APPLY_OPEN_COMMAND*)pProtocol;
  744. char szSentence[MAX_SENTENCE_LENGTH];
  745. int nLength = pApply->m_wLength - (sizeof(TRADE_APPLY_OPEN_COMMAND) - 1 - sizeof(pApply->m_szSentence));
  746. if (nLength >= MAX_SENTENCE_LENGTH)
  747. nLength = MAX_SENTENCE_LENGTH - 1;
  748. memset(szSentence, 0, sizeof(szSentence));
  749. memcpy(szSentence, pApply->m_szSentence, nLength);
  750. switch (m_cMenuState.m_nState)
  751. {
  752. case PLAYER_MENU_STATE_NORMAL:
  753. case PLAYER_MENU_STATE_TRADEOPEN:
  754. m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_TRADEOPEN, szSentence, nLength);
  755. break;
  756. case PLAYER_MENU_STATE_TEAMOPEN:
  757. if (m_cTeam.m_nFlag && m_cTeam.m_nID >= 0)
  758. g_Team[m_cTeam.m_nID].SetTeamClose();
  759. m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_TRADEOPEN, szSentence, nLength);
  760. break;
  761. }
  762. }
  763. #endif
  764. #ifdef _SERVER
  765. //-------------------------------------------------------------------------
  766. // 功能:收到客户端申请取消待交易状态
  767. //-------------------------------------------------------------------------
  768. void KPlayer::TradeApplyClose(BYTE* pProtocol)
  769. {
  770. m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_NORMAL);
  771. }
  772. #endif
  773. #ifdef _SERVER
  774. //-------------------------------------------------------------------------
  775. // 功能:收到客户端申请开始交易
  776. //-------------------------------------------------------------------------
  777. void KPlayer::TradeApplyStart(BYTE* pProtocol)
  778. {
  779. if (this->CheckTrading())
  780. return;
  781. TRADE_APPLY_START_COMMAND *pStart = (TRADE_APPLY_START_COMMAND*)pProtocol;
  782. int nPlayer;
  783. nPlayer = FindAroundPlayer(pStart->m_dwID);
  784. if (nPlayer < 0)
  785. return;
  786. if (Player[nPlayer].m_cMenuState.m_nState != PLAYER_MENU_STATE_TRADEOPEN)
  787. return;
  788. this->m_cTrade.m_nApplyIdx = nPlayer;
  789. TRADE_APPLY_START_SYNC sApply;
  790. sApply.ProtocolType = s2c_tradeapplystart;
  791. sApply.m_nDestIdx = this->m_nPlayerIndex;
  792. sApply.m_dwNpcId = Npc[m_nIndex].m_dwID;
  793. if (g_pServer)
  794. g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, (BYTE*)&sApply, sizeof(TRADE_APPLY_START_SYNC));
  795. }
  796. #endif
  797. #ifdef _SERVER
  798. //-------------------------------------------------------------------------
  799. // 功能:
  800. //-------------------------------------------------------------------------
  801. void KPlayer::TradeMoveMoney(BYTE* pProtocol)
  802. {
  803. if ( !CheckTrading() )
  804. return;
  805. if (this->m_cTrade.m_nTradeLock)
  806. return;
  807. int nMoney;
  808. TRADE_MOVE_MONEY_COMMAND *pMoney = (TRADE_MOVE_MONEY_COMMAND*)pProtocol;
  809. if (pMoney->m_nMoney < 0 || pMoney->m_nMoney > m_ItemList.GetEquipmentMoney())
  810. nMoney = 0;
  811. else
  812. nMoney = pMoney->m_nMoney;
  813. m_ItemList.TradeMoveMoney(nMoney);
  814. }
  815. #endif
  816. #ifdef _SERVER
  817. //-------------------------------------------------------------------------
  818. // 功能:执行或取消交易
  819. //-------------------------------------------------------------------------
  820. void KPlayer::TradeDecision(BYTE* pProtocol)
  821. {
  822. if ( !CheckTrading() )
  823. return;
  824. TRADE_DECISION_COMMAND *pDecision = (TRADE_DECISION_COMMAND*)pProtocol;
  825. if (pDecision->m_btDecision == 2) // 己方锁定
  826. {
  827. if (this->m_cTrade.m_nTradeLock == 0)
  828. {
  829. this->m_cTrade.m_nTradeLock = 1;
  830. this->m_cTrade.m_nTradeState = 0;
  831. Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState = 0;
  832. }
  833. SyncTradeState();
  834. return;
  835. }
  836. else if (pDecision->m_btDecision == 3) // 锁定取消
  837. {
  838. if (this->m_cTrade.m_nTradeLock == 1)
  839. {
  840. // 取消己方锁定的同时也取消了对方的锁定
  841. this->m_cTrade.m_nTradeLock = 0;
  842. this->m_cTrade.m_nTradeState = 0;
  843. Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock = 0;
  844. Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState = 0;
  845. }
  846. SyncTradeState();
  847. return;
  848. }
  849. else if (pDecision->m_btDecision == 4) // 取消确定
  850. {
  851. if (m_cTrade.m_nTradeLock == 1 && Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock == 1)
  852. {
  853. m_cTrade.m_nTradeState = 0;
  854. SyncTradeState();
  855. }
  856. return;
  857. }
  858. else if (pDecision->m_btDecision == 0) // 取消交易
  859. {
  860. int nDestIdx;
  861. nDestIdx = this->m_cTrade.m_nTradeDest;
  862. // 取消交易的数据恢复
  863. this->m_ItemList.RecoverTrade();
  864. this->m_ItemList.ClearRoom(room_trade);
  865. this->m_ItemList.ClearRoom(room_trade1);
  866. this->m_cTrade.Release();
  867. Player[nDestIdx].m_ItemList.RecoverTrade();
  868. Player[nDestIdx].m_ItemList.ClearRoom(room_trade);
  869. Player[nDestIdx].m_ItemList.ClearRoom(room_trade1);
  870. Player[nDestIdx].m_cTrade.Release();
  871. TRADE_DECISION_SYNC sSync;
  872. sSync.ProtocolType = s2c_tradedecision;
  873. sSync.m_btDecision = 0;
  874. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
  875. g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
  876. // 取消交易的状态恢复(备份状态一定不会是 trading)(己方)
  877. this->m_cMenuState.RestoreBackupState(m_nPlayerIndex);
  878. // 取消交易的状态恢复(备份状态一定不会是 trading)(对方)
  879. Player[nDestIdx].m_cMenuState.RestoreBackupState(nDestIdx);
  880. return;
  881. }
  882. else if (pDecision->m_btDecision == 1) // 执行交易
  883. {
  884. // 如果双方没有同时锁定,不能确定
  885. if (this->m_cTrade.m_nTradeLock != 1 ||
  886. Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock != 1)
  887. {
  888. SyncTradeState();
  889. return;
  890. }
  891. // 对方还没确定,通知对方自己已确定
  892. else if (Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState == 0)
  893. {
  894. m_cTrade.m_nTradeState = 1;
  895. SyncTradeState();
  896. return;
  897. }
  898. // 对方已确定,执行交易
  899. else
  900. {
  901. // 执行交易之前,先检测一下是否有错误
  902. // -------------------- 检查 money --------------------
  903. int nSM1, nSM2, nDM1, nDM2;
  904. int nDestIdx = m_cTrade.m_nTradeDest;
  905. nSM1 = m_ItemList.GetMoney(room_equipment);
  906. nSM2 = m_ItemList.GetMoney(room_trade);
  907. nDM1 = Player[nDestIdx].m_ItemList.GetMoney(room_equipment);
  908. nDM2 = Player[nDestIdx].m_ItemList.GetMoney(room_trade);
  909. if (nSM2 < 0 || nSM1 + nDM2 - nSM2 < 0)
  910. {
  911. this->m_ItemList.TradeMoveMoney(0);
  912. // 通知客户端钱有问题 not end
  913. return;
  914. }
  915. if (nDM2 < 0 || nDM1 + nSM2 - nDM2 < 0)
  916. {
  917. Player[nDestIdx].m_ItemList.TradeMoveMoney(0);
  918. // 通知客户端钱有问题 not end
  919. return;
  920. }
  921. // ------------------ 检查 money end ------------------
  922. // --------- 检查双方物品栏能否接受买进的物品 ---------
  923. int nSelfCanGet, nDestCanGet;
  924. // 判断己方物品栏能否接受买进的物品
  925. Player[nDestIdx].m_ItemList.GetTradeRoomItemInfo();
  926. nSelfCanGet = m_ItemList.TradeCheckCanPlace();
  927. ItemSet.BackItemInfo();
  928. // 判断对方物品栏能否接受买进的物品
  929. this->m_ItemList.GetTradeRoomItemInfo();
  930. nDestCanGet = Player[nDestIdx].m_ItemList.TradeCheckCanPlace();
  931. if (!nSelfCanGet || !nDestCanGet)
  932. {
  933. if (!nSelfCanGet)
  934. {
  935. this->m_cTrade.m_nTradeState = 0;
  936. // 通知客户端买进的东西放不下
  937. SHOW_MSG_SYNC sMsg;
  938. sMsg.ProtocolType = s2c_msgshow;
  939. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  940. sMsg.m_wMsgID = enumMSG_ID_TRADE_SELF_ROOM_FULL;
  941. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  942. sMsg.m_wMsgID = enumMSG_ID_TRADE_DEST_ROOM_FULL;
  943. g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  944. }
  945. if (!nDestCanGet)
  946. {
  947. Player[nDestIdx].m_cTrade.m_nTradeState = 0;
  948. // 通知客户端买进的东西放不下
  949. SHOW_MSG_SYNC sMsg;
  950. sMsg.ProtocolType = s2c_msgshow;
  951. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  952. sMsg.m_wMsgID = enumMSG_ID_TRADE_SELF_ROOM_FULL;
  953. g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  954. sMsg.m_wMsgID = enumMSG_ID_TRADE_DEST_ROOM_FULL;
  955. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  956. }
  957. SyncTradeState();
  958. return;
  959. }
  960. // ------- 检查双方物品栏能否接受买进的物品 end -------
  961. // 通知客户端交易完成
  962. TRADE_DECISION_SYNC sSync;
  963. sSync.ProtocolType = s2c_tradedecision;
  964. sSync.m_btDecision = 1;
  965. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
  966. g_pServer->PackDataToClient(Player[nDestIdx].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_DECISION_SYNC));
  967. // 服务器端结束交易状态
  968. m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_NORMAL);
  969. Player[nDestIdx].m_cMenuState.SetState(nDestIdx, PLAYER_MENU_STATE_NORMAL);
  970. this->m_cTrade.Release();
  971. Player[nDestIdx].m_cTrade.Release();
  972. // 交易中金钱的交换
  973. if (nSM2 <= nDM2)
  974. {
  975. this->Earn(nDM2 - nSM2);
  976. Player[nDestIdx].Pay(nDM2 - nSM2);
  977. }
  978. else
  979. {
  980. this->Pay(nSM2 - nDM2);
  981. Player[nDestIdx].Earn(nSM2 - nDM2);
  982. }
  983. //--------------- 交易中物品的交换 ---------------------
  984. // 对方的物品给己方
  985. int nPos;
  986. nPos = 0;
  987. while (1)
  988. {
  989. if (nPos >= TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT)
  990. break;
  991. if (!ItemSet.m_psBackItemInfo[nPos].m_nIdx)
  992. break;
  993. // 对方去除此物品
  994. Player[nDestIdx].m_ItemList.Remove(ItemSet.m_psBackItemInfo[nPos].m_nIdx);
  995. // 己方得到此物品
  996. m_ItemList.Add(
  997. ItemSet.m_psBackItemInfo[nPos].m_nIdx,
  998. pos_equiproom,
  999. ItemSet.m_psBackItemInfo[nPos].m_nX,
  1000. ItemSet.m_psBackItemInfo[nPos].m_nY);
  1001. nPos++;
  1002. }
  1003. // 己方的物品给对方
  1004. nPos = 0;
  1005. while (1)
  1006. {
  1007. if (nPos >= TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT)
  1008. break;
  1009. if (!ItemSet.m_psItemInfo[nPos].m_nIdx)
  1010. break;
  1011. // 己方去除此物品
  1012. this->m_ItemList.Remove(ItemSet.m_psItemInfo[nPos].m_nIdx);
  1013. // 对方得到此物品
  1014. Player[nDestIdx].m_ItemList.Add(
  1015. ItemSet.m_psItemInfo[nPos].m_nIdx,
  1016. pos_equiproom,
  1017. ItemSet.m_psItemInfo[nPos].m_nX,
  1018. ItemSet.m_psItemInfo[nPos].m_nY);
  1019. nPos++;
  1020. }
  1021. //------------- 交易中物品的交换 end -------------------
  1022. return;
  1023. }
  1024. }
  1025. }
  1026. #endif
  1027. #ifdef _SERVER
  1028. //-------------------------------------------------------------------------
  1029. // 功能:执行或取消交易
  1030. //-------------------------------------------------------------------------
  1031. void KPlayer::c2sTradeReplyStart(BYTE* pProtocol)
  1032. {
  1033. if (this->CheckTrading())
  1034. return;
  1035. if (!pProtocol)
  1036. return;
  1037. TRADE_REPLY_START_COMMAND *pReply = (TRADE_REPLY_START_COMMAND*)pProtocol;
  1038. int nPlayerIdx = pReply->m_nDestIdx;
  1039. if (nPlayerIdx <= 0 || nPlayerIdx >= MAX_PLAYER)
  1040. return;
  1041. if (Player[nPlayerIdx].m_nIndex <= 0)
  1042. return;
  1043. if (Player[nPlayerIdx].m_cTrade.m_nApplyIdx != this->m_nPlayerIndex)
  1044. return;
  1045. // 拒绝
  1046. if (pReply->m_bDecision == 0)
  1047. {
  1048. SHOW_MSG_SYNC sMsg;
  1049. sMsg.ProtocolType = s2c_msgshow;
  1050. sMsg.m_wMsgID = enumMSG_ID_TRADE_REFUSE_APPLY;
  1051. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  1052. sMsg.m_lpBuf = (LPVOID)Npc[m_nIndex].m_dwID;
  1053. g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1054. sMsg.m_lpBuf = 0;
  1055. return;
  1056. }
  1057. if (this->m_cMenuState.m_nState != PLAYER_MENU_STATE_TRADEOPEN)
  1058. {
  1059. return;
  1060. }
  1061. // 如果处于队伍开放状态,关闭之
  1062. if (Player[nPlayerIdx].m_cMenuState.m_nState == PLAYER_MENU_STATE_TEAMOPEN)
  1063. {
  1064. PLAYER_TEAM_OPEN_CLOSE sClose;
  1065. sClose.m_btOpenClose = 0;
  1066. Player[nPlayerIdx].SetTeamState((BYTE*)&sClose);
  1067. }
  1068. // 打坐的话,要站起来
  1069. if (Npc[m_nIndex].m_Doing == do_sit)
  1070. {
  1071. Npc[m_nIndex].SendCommand(do_stand);
  1072. }
  1073. if (Npc[Player[nPlayerIdx].m_nIndex].m_Doing == do_sit)
  1074. {
  1075. Npc[Player[nPlayerIdx].m_nIndex].SendCommand(do_stand);
  1076. }
  1077. // 服务器的处理:改变状态,备份数据
  1078. this->m_ItemList.StartTrade();
  1079. this->m_cTrade.Release();
  1080. this->m_cTrade.StartTrade(nPlayerIdx);
  1081. this->m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_TRADING, NULL, 0, Npc[Player[nPlayerIdx].m_nIndex].m_dwID);
  1082. Player[nPlayerIdx].m_ItemList.StartTrade();
  1083. Player[nPlayerIdx].m_cTrade.Release();
  1084. Player[nPlayerIdx].m_cTrade.StartTrade(m_nPlayerIndex);
  1085. Player[nPlayerIdx].m_cMenuState.SetState(nPlayerIdx, PLAYER_MENU_STATE_TRADING, NULL, 0, Npc[m_nIndex].m_dwID);
  1086. }
  1087. #endif
  1088. //-------------------------------------------------------------------------
  1089. // 功能:给交易双方的客户端发送交易状态信息
  1090. //-------------------------------------------------------------------------
  1091. #ifdef _SERVER
  1092. void KPlayer::SyncTradeState()
  1093. {
  1094. if ( !CheckTrading() )
  1095. return;
  1096. TRADE_STATE_SYNC sSync;
  1097. sSync.ProtocolType = s2c_tradepressoksync;
  1098. sSync.m_btSelfLock = this->m_cTrade.m_nTradeLock;
  1099. sSync.m_btDestLock = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock;
  1100. sSync.m_btSelfOk = m_cTrade.m_nTradeState;
  1101. sSync.m_btDestOk = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState;
  1102. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_STATE_SYNC));
  1103. sSync.m_btSelfLock = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeLock;
  1104. sSync.m_btDestLock = m_cTrade.m_nTradeLock;
  1105. sSync.m_btSelfOk = Player[m_cTrade.m_nTradeDest].m_cTrade.m_nTradeState;
  1106. sSync.m_btDestOk = m_cTrade.m_nTradeState;
  1107. g_pServer->PackDataToClient(Player[m_cTrade.m_nTradeDest].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(TRADE_STATE_SYNC));
  1108. }
  1109. #endif
  1110. //-------------------------------------------------------------------------
  1111. // 功能:发送自己装备在身上的装备信息给别人看
  1112. //-------------------------------------------------------------------------
  1113. #ifdef _SERVER
  1114. void KPlayer::SendEquipItemInfo(int nTargetPlayer)
  1115. {
  1116. if (nTargetPlayer <= 0 || nTargetPlayer >= MAX_PLAYER || Player[nTargetPlayer].m_nIndex <= 0)
  1117. return;
  1118. int nIdx, i, j;
  1119. SViewItemInfo *pInfo;
  1120. VIEW_EQUIP_SYNC sView;
  1121. sView.ProtocolType = s2c_viewequip;
  1122. sView.m_dwNpcID = Npc[m_nIndex].m_dwID;
  1123. for (i = 0; i < itempart_num; i++)
  1124. {
  1125. nIdx = m_ItemList.m_EquipItem[i];
  1126. pInfo = &sView.m_sInfo[i];
  1127. if (nIdx <= 0)
  1128. {
  1129. memset(pInfo, 0, sizeof(SViewItemInfo));
  1130. continue;
  1131. }
  1132. pInfo->m_nID = Item[nIdx].GetID();
  1133. pInfo->m_btGenre = Item[nIdx].GetGenre();
  1134. pInfo->m_btDetail = Item[nIdx].GetDetailType();
  1135. pInfo->m_btParticur = Item[nIdx].GetParticular();
  1136. pInfo->m_btSeries = Item[nIdx].GetSeries();
  1137. pInfo->m_btLevel = Item[nIdx].GetLevel();
  1138. pInfo->m_btLuck = Item[nIdx].m_GeneratorParam.nLuck;
  1139. pInfo->m_dwRandomSeed = Item[nIdx].m_GeneratorParam.uRandomSeed;
  1140. pInfo->m_wVersion = Item[nIdx].m_GeneratorParam.nVersion;
  1141. for (j = 0; j < 6; j++)
  1142. pInfo->m_btMagicLevel[j] = (BYTE)Item[nIdx].m_GeneratorParam.nGeneratorLevel[j];
  1143. }
  1144. g_pServer->PackDataToClient(Player[nTargetPlayer].m_nNetConnectIdx, (BYTE*)&sView, sizeof(sView));
  1145. }
  1146. #endif
  1147. #ifdef _SERVER
  1148. //-------------------------------------------------------------------------
  1149. // 功能:主角与传送门的相关的函数
  1150. //-------------------------------------------------------------------------
  1151. void KPlayer::UseTownPortal()
  1152. {
  1153. if (m_nPlayerIndex <= 0)
  1154. return;
  1155. if (m_nIndex <= 0)
  1156. return;
  1157. if (Npc[m_nIndex].m_SubWorldIndex < 0)
  1158. return;
  1159. if (!Npc[m_nIndex].m_FightMode)
  1160. {
  1161. return;
  1162. }
  1163. m_sPortalPos.m_nSubWorldId = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_SubWorldID;
  1164. Npc[m_nIndex].GetMpsPos(&m_sPortalPos.m_nMpsX, &m_sPortalPos.m_nMpsY);
  1165. m_sPortalPos.m_nTime = TOWN_PORTAL_TIME;
  1166. Npc[m_nIndex].ChangeWorld(m_sDeathRevivalPos.m_nSubWorldID, m_sDeathRevivalPos.m_nMpsX, m_sDeathRevivalPos.m_nMpsY);
  1167. Npc[m_nIndex].SetFightMode(0);
  1168. }
  1169. void KPlayer::BackToTownPortal()
  1170. {
  1171. if (m_nPlayerIndex <= 0)
  1172. return;
  1173. if (m_nIndex <= 0)
  1174. return;
  1175. if (m_sPortalPos.m_nTime <= 0)
  1176. return;
  1177. Npc[m_nIndex].ChangeWorld(m_sPortalPos.m_nSubWorldId, m_sPortalPos.m_nMpsX, m_sPortalPos.m_nMpsY);
  1178. m_sPortalPos.m_nSubWorldId = 0;
  1179. m_sPortalPos.m_nTime = 0;
  1180. m_sPortalPos.m_nMpsX = 0;
  1181. m_sPortalPos.m_nMpsY = 0;
  1182. Npc[m_nIndex].SetFightMode(TRUE);
  1183. }
  1184. #endif
  1185. #ifdef _SERVER
  1186. //-------------------------------------------------------------------------
  1187. // 功能:主角死后重生
  1188. //-------------------------------------------------------------------------
  1189. void KPlayer::Revive(int nType)
  1190. {
  1191. int nSubWorldID = 0;
  1192. int nMpsX = 0, nMpsY = 0;
  1193. NPC_REVIVE_SYNC Sync;
  1194. Sync.ProtocolType = s2c_playerrevive;
  1195. Sync.ID = Npc[m_nIndex].m_dwID;
  1196. Sync.Type = nType;
  1197. g_pServer->PackDataToClient(m_nNetConnectIdx, (const void*)&Sync, sizeof(NPC_REVIVE_SYNC));
  1198. Npc[m_nIndex].BroadCastRevive(nType);
  1199. switch(nType)
  1200. {
  1201. case REMOTE_REVIVE_TYPE:
  1202. GetDeathRevivalPos(&nSubWorldID, &nMpsX, &nMpsY);
  1203. Npc[m_nIndex].ChangeWorld(nSubWorldID, nMpsX, nMpsY);
  1204. Npc[m_nIndex].m_FightMode = 0;
  1205. break;
  1206. case LOCAL_REVIVE_TYPE:
  1207. Npc[m_nIndex].m_FightMode = 1;
  1208. break;
  1209. default:
  1210. break;
  1211. }
  1212. Npc[m_nIndex].m_CurrentLife = Npc[m_nIndex].m_CurrentLifeMax;
  1213. Npc[m_nIndex].m_CurrentMana = Npc[m_nIndex].m_CurrentManaMax;
  1214. Npc[m_nIndex].m_CurrentStamina = Npc[m_nIndex].m_CurrentStaminaMax;
  1215. //RestoreLiveData();
  1216. Npc[m_nIndex].SendCommand(do_revive);
  1217. }
  1218. void KPlayer::RestoreLiveData()
  1219. {
  1220. Npc[m_nIndex].RestoreNpcBaseInfo();
  1221. }
  1222. BOOL KPlayer::Pay(int nMoney)
  1223. {
  1224. if (nMoney < 0)
  1225. return FALSE;
  1226. return m_ItemList.CostMoney(nMoney);
  1227. }
  1228. BOOL KPlayer::PrePay(int nMoney)
  1229. {
  1230. if (nMoney < 0)
  1231. return FALSE;
  1232. if (Pay(nMoney))
  1233. {
  1234. m_nPrePayMoney = nMoney;
  1235. return TRUE;
  1236. }
  1237. else
  1238. {
  1239. return FALSE;
  1240. }
  1241. }
  1242. BOOL KPlayer::Earn(int nMoney)
  1243. {
  1244. if (nMoney < 0)
  1245. return FALSE;
  1246. return m_ItemList.AddMoney(room_equipment, nMoney);
  1247. }
  1248. //当服务器从数据库中获得玩家全部数据,并加载之后,使该玩家有效
  1249. void KPlayer::LaunchPlayer()
  1250. {
  1251. int nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
  1252. int nRegion = Npc[m_nIndex].m_RegionIndex;
  1253. int nX = Npc[m_nIndex].m_MapX;
  1254. int nY = Npc[m_nIndex].m_MapY;
  1255. int nOffX = Npc[m_nIndex].m_OffX;
  1256. int nOffY = Npc[m_nIndex].m_OffY;
  1257. SubWorld[nSubWorld].AddPlayer(nRegion, m_nPlayerIndex);
  1258. m_ulLastSaveTime = g_SubWorldSet.GetGameTime();
  1259. if (SubWorld[nSubWorld].m_Region[nRegion].GetBarrierMin(nX, nY, nOffX, nOffY, FALSE) != Obstacle_NULL)
  1260. {
  1261. Npc[m_nIndex].ChangeWorld(m_sLoginRevivalPos.m_nSubWorldID, m_sLoginRevivalPos.m_nMpsX, m_sLoginRevivalPos.m_nMpsY);
  1262. }
  1263. }
  1264. #endif
  1265. BOOL KPlayer::ExecuteScript(char * ScriptFileName, char * szFunName, int nParam)
  1266. {
  1267. if (!ScriptFileName || !ScriptFileName[0] || !szFunName  || !szFunName[0]) return FALSE;
  1268. return ExecuteScript(g_FileName2Id(ScriptFileName), szFunName, nParam);
  1269. }
  1270. #define MAX_TRYEXECUTESCRIPT_COUNT 5
  1271. BOOL KPlayer::ExecuteScript(DWORD dwScriptId,  char * szFunName, int nParam)
  1272. {
  1273. /* bool bCanExecuteScript = true;
  1274.   //当前脚本未置空
  1275.   if (m_bWaitingPlayerFeedBack)
  1276.   {
  1277. if (Npc[m_nIndex].m_ActionScriptID && (dwScriptId != Npc[m_nIndex].m_ActionScriptID))
  1278. {
  1279. m_btTryExecuteScriptTimes ++;
  1280. if (m_btTryExecuteScriptTimes <= MAX_TRYEXECUTESCRIPT_COUNT)//最大尝试执行脚本的次数。如果超过后,就执行当前脚本,并放弃原来的脚本。
  1281. {
  1282. bCanExecuteScript = false;
  1283. }
  1284. else
  1285. {
  1286. m_btTryExecuteScriptTimes = 0;
  1287. m_bWaitingPlayerFeedBack = false;
  1288. Npc[m_nIndex].m_ActionScriptID = 0;
  1289. }
  1290. }
  1291. }
  1292.   if (!bCanExecuteScript) return FALSE;
  1293. */
  1294. try
  1295. {
  1296. m_btTryExecuteScriptTimes = 0;
  1297. bool bExecuteScriptMistake = true;
  1298. KLuaScript * pScript = (KLuaScript* )g_GetScript(dwScriptId);
  1299. if (pScript)
  1300. {
  1301. Npc[m_nIndex].m_ActionScriptID = dwScriptId;
  1302. Lua_PushNumber(pScript->m_LuaState, m_nPlayerIndex);
  1303. pScript->SetGlobalName(SCRIPT_PLAYERINDEX);
  1304. Lua_PushNumber(pScript->m_LuaState, m_dwID);
  1305. pScript->SetGlobalName(SCRIPT_PLAYERID);
  1306. Lua_PushNumber(pScript->m_LuaState, Npc[m_nIndex].m_SubWorldIndex);
  1307. pScript->SetGlobalName(SCRIPT_SUBWORLDINDEX);
  1308. int nTopIndex = 0;
  1309. pScript->SafeCallBegin(&nTopIndex);
  1310. if (pScript->CallFunction(szFunName,0, "d", nParam)) 
  1311. {
  1312. bExecuteScriptMistake = false;
  1313. }
  1314. pScript->SafeCallEnd(nTopIndex);
  1315. }
  1316. if (bExecuteScriptMistake)
  1317. {
  1318. m_bWaitingPlayerFeedBack = false;
  1319. m_btTryExecuteScriptTimes = 0;
  1320. Npc[m_nIndex].m_ActionScriptID = 0;
  1321. return FALSE;
  1322. }
  1323. return TRUE;
  1324. }
  1325. catch(...)
  1326. {
  1327. printf("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId);
  1328. m_bWaitingPlayerFeedBack = false;
  1329. m_btTryExecuteScriptTimes = 0;
  1330. Npc[m_nIndex].m_ActionScriptID = 0;
  1331. return FALSE;
  1332. }
  1333. return TRUE;
  1334. }
  1335. BOOL KPlayer::ExecuteScript(DWORD dwScriptId, char * szFunName, char *  szParams)
  1336. {
  1337. /*bool bCanExecuteScript = true;
  1338.   //当前脚本未置空
  1339.   if (m_bWaitingPlayerFeedBack)
  1340.   {
  1341. if (Npc[m_nIndex].m_ActionScriptID && (dwScriptId != Npc[m_nIndex].m_ActionScriptID))
  1342. {
  1343. m_btTryExecuteScriptTimes ++;
  1344. if (m_btTryExecuteScriptTimes <= MAX_TRYEXECUTESCRIPT_COUNT)//最大尝试执行脚本的次数。如果超过后,就执行当前脚本,并放弃原来的脚本。
  1345. {
  1346. bCanExecuteScript = false;
  1347. }
  1348. else
  1349. {
  1350. m_btTryExecuteScriptTimes = 0;
  1351. m_bWaitingPlayerFeedBack = false;
  1352. Npc[m_nIndex].m_ActionScriptID = 0;
  1353. }
  1354. }
  1355. }
  1356.   bCanExecuteScript = true;//test
  1357.   
  1358. if (!bCanExecuteScript) return FALSE;
  1359. */
  1360. try
  1361. {
  1362. m_btTryExecuteScriptTimes = 0;
  1363. bool bExecuteScriptMistake = true;
  1364. KLuaScript * pScript = (KLuaScript* )g_GetScript(dwScriptId);
  1365. int nTopIndex = 0;
  1366. if (pScript)
  1367. {
  1368. Npc[m_nIndex].m_ActionScriptID = dwScriptId;
  1369. Lua_PushNumber(pScript->m_LuaState, m_nPlayerIndex);
  1370. pScript->SetGlobalName(SCRIPT_PLAYERINDEX);
  1371. Lua_PushNumber(pScript->m_LuaState, m_dwID);
  1372. pScript->SetGlobalName(SCRIPT_PLAYERID);
  1373. Lua_PushNumber(pScript->m_LuaState, Npc[m_nIndex].m_SubWorldIndex);
  1374. pScript->SetGlobalName(SCRIPT_SUBWORLDINDEX);
  1375. pScript->SafeCallBegin(&nTopIndex);
  1376. if ( (!szParams) || !szParams[0]) 
  1377. {
  1378. if (pScript->CallFunction(szFunName, 0,""))
  1379. {
  1380. bExecuteScriptMistake = false;
  1381. }
  1382. }
  1383. else
  1384. {
  1385. if (pScript->CallFunction(szFunName,0, "sd", szParams,0)) 
  1386. {
  1387. bExecuteScriptMistake = false;
  1388. }
  1389. }
  1390. pScript->SafeCallEnd(nTopIndex);
  1391. }
  1392. if (bExecuteScriptMistake)
  1393. {
  1394. m_bWaitingPlayerFeedBack = false;
  1395. m_btTryExecuteScriptTimes = 0;
  1396. Npc[m_nIndex].m_ActionScriptID = 0;
  1397. return FALSE;
  1398. }
  1399. return TRUE;
  1400. }
  1401. catch(...)
  1402. {
  1403. printf("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId);
  1404. m_bWaitingPlayerFeedBack = false;
  1405. m_btTryExecuteScriptTimes = 0;
  1406. Npc[m_nIndex].m_ActionScriptID = 0;
  1407. return FALSE;
  1408. }
  1409. return TRUE;
  1410. }
  1411. BOOL KPlayer::ExecuteScript(char * ScriptFileName, char * szFunName, char *  szParams)
  1412. {
  1413. if (!ScriptFileName || !ScriptFileName[0] || !szFunName  || !szFunName[0]) return FALSE;
  1414. DWORD dwScriptId = g_FileName2Id(ScriptFileName);
  1415. return ExecuteScript(dwScriptId, szFunName, szParams);
  1416. }
  1417. BOOL KPlayer::DoScript(char * ScriptCommand)
  1418. {
  1419. if (NULL == ScriptCommand) return FALSE;
  1420. KLuaScript *Script = new KLuaScript;
  1421. Script->Init();
  1422. Script->RegisterFunctions(GameScriptFuns, g_GetGameScriptFunNum());
  1423. //GM Standand Script Functions 
  1424. Script->Load("\script\gmscript.lua");
  1425. Lua_PushNumber(Script->m_LuaState, m_nPlayerIndex);
  1426. Script->SetGlobalName(SCRIPT_PLAYERINDEX);
  1427. Lua_PushNumber(Script->m_LuaState, m_dwID);
  1428. Script->SetGlobalName(SCRIPT_PLAYERID);
  1429. Lua_PushNumber(Script->m_LuaState, Npc[m_nIndex].m_SubWorldIndex);
  1430. Script->SetGlobalName(SCRIPT_SUBWORLDINDEX);
  1431. if (Script->LoadBuffer((PBYTE)ScriptCommand, strlen(ScriptCommand))) 
  1432. {
  1433. BOOL bResult = Script->ExecuteCode();
  1434. delete Script; //Question!
  1435. return bResult;
  1436. }
  1437. delete Script; //Question!
  1438. return FALSE;
  1439. }
  1440. void KPlayer::DoScriptAction(PLAYER_SCRIPTACTION_SYNC * pUIInfo) //要求显示某个UI界面
  1441. {
  1442. if (!pUIInfo) return;
  1443. //服务器端脚本时
  1444. if (pUIInfo->m_bParam2 == 1)
  1445. {
  1446. #ifdef _SERVER
  1447. pUIInfo->ProtocolType = (BYTE)s2c_scriptaction;
  1448. pUIInfo->m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - MAX_SCIRPTACTION_BUFFERNUM + pUIInfo->m_nBufferLen - 1;
  1449. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)pUIInfo, pUIInfo->m_wProtocolLong + 1 );
  1450. #else
  1451. }
  1452. else //客户端脚本要求显示脚本 直接运行
  1453. {
  1454. OnScriptAction((PLAYER_SCRIPTACTION_SYNC *)pUIInfo);
  1455. #endif
  1456. }
  1457. }
  1458. //服务器端获知玩家选择了某项后,处理~~
  1459. void KPlayer::ProcessPlayerSelectFromUI(BYTE* pProtocol) // 处理当玩家从选择菜单选择某项时的操作
  1460. {
  1461. PLAYER_SELECTUI_COMMAND * pSelUI = (PLAYER_SELECTUI_COMMAND*) pProtocol;
  1462. m_bWaitingPlayerFeedBack = false;
  1463. //如果返回负数,表示退出该脚本执行环境
  1464. if (pSelUI->nSelectIndex < 0) m_nAvailableAnswerNum = 0;
  1465. if (m_nAvailableAnswerNum > pSelUI->nSelectIndex)
  1466. {
  1467. if (m_szTaskAnswerFun[pSelUI->nSelectIndex][0])
  1468. {
  1469. // g_SetFilePath("\script");
  1470. if (m_nIndex)
  1471. {
  1472. ExecuteScript(Npc[m_nIndex].m_ActionScriptID, m_szTaskAnswerFun[pSelUI->nSelectIndex], pSelUI->nSelectIndex);
  1473. }
  1474. }
  1475. }
  1476. }
  1477. #ifndef _SERVER
  1478. //玩家在界面交互后,选择了某项后,向服务器端发送
  1479. void KPlayer::OnSelectFromUI(PLAYER_SELECTUI_COMMAND * pSelectUI, UIInfo eUIInfo) //当玩家从选择框中选择某项后,将向服务器发送
  1480. {
  1481. if (!pSelectUI) return;
  1482. switch(eUIInfo)
  1483. {
  1484. case UI_SELECTDIALOG:
  1485. {
  1486. if (g_bUISelIntelActiveWithServer)
  1487. {
  1488. pSelectUI->ProtocolType = (BYTE)c2s_playerselui;
  1489. if (g_pClient)
  1490. g_pClient->SendPackToServer((BYTE*)pSelectUI, sizeof(PLAYER_SELECTUI_COMMAND));
  1491. }
  1492. else
  1493. {
  1494. ProcessPlayerSelectFromUI((BYTE *)pSelectUI); // 处理当玩家从选择菜单选择某项时的操作
  1495. }
  1496. }
  1497. break;
  1498. case UI_TALKDIALOG:
  1499. {
  1500. if (g_bUISpeakActiveWithServer)
  1501. {
  1502. pSelectUI->ProtocolType = (BYTE)c2s_playerselui;
  1503. if (g_pClient)
  1504. g_pClient->SendPackToServer((BYTE*)pSelectUI, sizeof(PLAYER_SELECTUI_COMMAND));
  1505. }
  1506. else
  1507. {
  1508. ProcessPlayerSelectFromUI((BYTE *)pSelectUI); // 处理当玩家从选择菜单选择某项时的操作
  1509. }
  1510. }break;
  1511. }
  1512. }
  1513. #endif
  1514. //-------------------------------------------------------------------------
  1515. // 功能:获得通知某好友上线了
  1516. //-------------------------------------------------------------------------
  1517. void KPlayer::ChatFriendOnLine(DWORD dwID, int nFriendIdx)
  1518. {
  1519. if (nFriendIdx <= 0)
  1520. return;
  1521. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  1522. {
  1523. if (m_cChat.m_cFriendTeam[i].m_nFriendNo == 0)
  1524. continue;
  1525. CChatFriend *pFriend;
  1526. pFriend = (CChatFriend*)m_cChat.m_cFriendTeam[i].m_cEveryOne.GetHead();
  1527. while (pFriend)
  1528. {
  1529. if (pFriend->m_dwID == dwID)
  1530. {
  1531. pFriend->m_nPlayerIdx = nFriendIdx;
  1532. #ifdef _SERVER
  1533. CHAT_FRIEND_ONLINE_SYNC sFriend;
  1534. sFriend.ProtocolType = s2c_chatfriendonline;
  1535. sFriend.m_dwID = dwID;
  1536. sFriend.m_nPlayerIdx = nFriendIdx;
  1537. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sFriend, sizeof(CHAT_FRIEND_ONLINE_SYNC));
  1538. #else
  1539. // 通知界面有好友上线
  1540. KUiPlayerItem sPlayer;
  1541. strcpy(sPlayer.Name, pFriend->m_szName);
  1542. sPlayer.uId = dwID;
  1543. sPlayer.nIndex = nFriendIdx;
  1544. sPlayer.nData = CHAT_S_ONLINE;
  1545. CoreDataChanged(GDCNI_CHAT_FRIEND_STATUS, (unsigned int)&sPlayer, i);
  1546. KSystemMessage sMsg;
  1547. sprintf(sMsg.szMessage, MSG_CHAT_FRIEND_ONLINE, pFriend->m_szName);
  1548. sMsg.eType = SMT_NORMAL;
  1549. sMsg.byConfirmType = SMCT_NONE;
  1550. sMsg.byPriority = 0;
  1551. sMsg.byParamSize = 0;
  1552. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1553. #endif
  1554. return;
  1555. }
  1556. pFriend = (CChatFriend*)pFriend->GetNext();
  1557. }
  1558. }
  1559. #ifdef _SERVER
  1560. // 如果没找到,说明本方已经删除了对方,必须通知对方删除
  1561. Player[nFriendIdx].m_cChat.DeleteFriendData(m_dwID, nFriendIdx);
  1562. #endif
  1563. }
  1564. // 获得当前门派名称
  1565. void KPlayer::GetFactionName(char *lpszName, int nSize)
  1566. {
  1567. this->m_cFaction.GetCurFactionName(lpszName);
  1568. return;
  1569. }
  1570. #ifdef _SERVER
  1571. void KPlayer::S2CExecuteScript(char * ScriptName, char * szParam = NULL)
  1572. {
  1573. if (!ScriptName || (!ScriptName[0])) return; 
  1574. PLAYER_SCRIPTACTION_SYNC  ScriptAction;
  1575. ScriptAction.m_nOperateType = SCRIPTACTION_EXESCRIPT;
  1576. ScriptAction.ProtocolType = s2c_scriptaction;
  1577. char * script = NULL;
  1578. if (szParam == NULL || szParam[0] == 0) 
  1579. {
  1580. ScriptAction.m_nBufferLen = strlen(ScriptName) + 1 ;
  1581. strcpy(ScriptAction.m_pContent, ScriptName);
  1582. }
  1583. else
  1584. {
  1585. ScriptAction.m_nBufferLen = strlen(ScriptName) + 2 + strlen(szParam);
  1586. sprintf(ScriptAction.m_pContent, "%s|%s", ScriptName, szParam);
  1587. }
  1588. ScriptAction.m_wProtocolLong = sizeof(PLAYER_SCRIPTACTION_SYNC) - 300 + ScriptAction.m_nBufferLen - 1;
  1589. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&ScriptAction, sizeof(PLAYER_SCRIPTACTION_SYNC) - 300 + ScriptAction.m_nBufferLen);
  1590. }
  1591. #endif
  1592. #ifndef _SERVER
  1593. void KPlayer::OnScriptAction(PLAYER_SCRIPTACTION_SYNC * pMsg)
  1594. {
  1595. PLAYER_SCRIPTACTION_SYNC * pScriptAction = (PLAYER_SCRIPTACTION_SYNC *)pMsg;
  1596. char szString[1000];
  1597. switch(pScriptAction->m_nOperateType)
  1598. {
  1599. case SCRIPTACTION_UISHOW:
  1600. {
  1601. switch(pScriptAction->m_bUIId)
  1602. {
  1603. case UI_SELECTDIALOG://通知客户端显示选择窗口
  1604. {
  1605. KUiQuestionAndAnswer *pQuest = NULL;
  1606. if (pScriptAction->m_nBufferLen <= 0) break;
  1607. if (pScriptAction->m_bOptionNum <= 0)
  1608. pQuest = (KUiQuestionAndAnswer *)malloc(sizeof(KUiQuestionAndAnswer));
  1609. else
  1610. pQuest = (KUiQuestionAndAnswer *)malloc(sizeof(KUiQuestionAndAnswer) + sizeof(KUiAnswer) * (pScriptAction->m_bOptionNum - 1));
  1611. char strContent[1024];
  1612. char * pAnswer = NULL;
  1613. pQuest->AnswerCount = 0;
  1614. //主信息为字符串
  1615. if (pScriptAction->m_bParam1 == 0)
  1616. {
  1617. g_StrCpyLen(strContent, pScriptAction->m_pContent,  pScriptAction->m_nBufferLen + 1);
  1618. pAnswer = strstr(strContent, "|");
  1619. if (!pAnswer)
  1620. {
  1621. pScriptAction->m_bOptionNum = 0;
  1622. pQuest->AnswerCount = 0;
  1623. }
  1624. else
  1625. *pAnswer++ = 0;
  1626. g_StrCpyLen(pQuest->Question, strContent, sizeof(pQuest->Question));
  1627. pQuest->QuestionLen = TEncodeText(pQuest->Question, strlen(pQuest->Question));
  1628. }
  1629. //主信息为数字标识
  1630. else 
  1631. {
  1632. g_StrCpyLen(pQuest->Question, g_GetStringRes(*(int *)pScriptAction->m_pContent, szString, 1000), sizeof(pQuest->Question));
  1633. pQuest->QuestionLen = TEncodeText(pQuest->Question, strlen(pQuest->Question));
  1634. g_StrCpyLen(strContent, pScriptAction->m_pContent + sizeof(int), pScriptAction->m_nBufferLen - sizeof(int) + 1);
  1635. pAnswer = strContent + 1;
  1636. }
  1637. for (int i = 0; i < pScriptAction->m_bOptionNum; i ++)
  1638. {
  1639. char * pNewAnswer = strstr(pAnswer, "|");
  1640. if (pNewAnswer)
  1641. {
  1642. *pNewAnswer = 0;
  1643. strcpy(pQuest->Answer[i].AnswerText, pAnswer);
  1644. pQuest->Answer[i].AnswerLen = -1;
  1645. pAnswer = pNewAnswer + 1;
  1646. }
  1647. else
  1648. {
  1649. strcpy(pQuest->Answer[i].AnswerText, pAnswer);
  1650. pQuest->Answer[i].AnswerLen = -1;
  1651. pQuest->AnswerCount = i + 1;
  1652. break;
  1653. }
  1654. }
  1655. g_bUISelIntelActiveWithServer = pScriptAction->m_bParam2;
  1656. g_bUISelLastSelCount = pQuest->AnswerCount;
  1657. CoreDataChanged(GDCNI_QUESTION_CHOOSE,(unsigned int) pQuest, 0);
  1658. free(pQuest);
  1659. pQuest = NULL;
  1660. }
  1661. break;
  1662. case UI_TALKDIALOG: 
  1663. {
  1664. BOOL bUsingSpeakId = pScriptAction->m_bParam1;
  1665. int  nSentenceCount = pScriptAction->m_bOptionNum;
  1666. if (nSentenceCount <= 0) return ;
  1667. KUiInformationParam *pSpeakList  = new KUiInformationParam[nSentenceCount];
  1668. memset(pSpeakList, 0, sizeof(KUiInformationParam) * nSentenceCount);
  1669. char * pAnswer = new char [pScriptAction->m_nBufferLen + 1];
  1670. char * pBackupAnswer = pAnswer;
  1671. g_StrCpyLen(pAnswer, pScriptAction->m_pContent, pScriptAction->m_nBufferLen + 1);
  1672. int nCount = 0;
  1673. for (int i = 0; i < pScriptAction->m_bOptionNum; i ++)
  1674. {
  1675. char * pNewAnswer = strstr(pAnswer, "|");
  1676. if (pNewAnswer)
  1677. {
  1678. *pNewAnswer = 0;
  1679. if (!bUsingSpeakId)
  1680. {
  1681. strcpy(pSpeakList[i].sInformation, pAnswer);
  1682. }
  1683. else
  1684. {
  1685. strcpy(pSpeakList[i].sInformation, g_GetStringRes(atoi(pAnswer), szString, sizeof(szString)));
  1686. }
  1687. if (i < pScriptAction->m_bOptionNum - 1)
  1688. strcpy(pSpeakList[i].sConfirmText, "继续");
  1689. else 
  1690. {
  1691. strcpy(pSpeakList[i].sConfirmText, "完成");
  1692. if (pScriptAction->m_nParam == 1)
  1693. pSpeakList[i].bNeedConfirmNotify = TRUE;
  1694. }
  1695. pSpeakList[i].nInforLen = TEncodeText(pSpeakList[i].sInformation, strlen(pSpeakList[i].sInformation));
  1696. pAnswer = pNewAnswer + 1;
  1697. }
  1698. else
  1699. {
  1700. if (!bUsingSpeakId)
  1701. {
  1702. strcpy(pSpeakList[i].sInformation, pAnswer);
  1703. }
  1704. else
  1705. {
  1706. strcpy(pSpeakList[i].sInformation, g_GetStringRes(atoi(pAnswer), szString ,sizeof(szString)));
  1707. }
  1708. strcpy(pSpeakList[i].sConfirmText, "完成");
  1709. if (pScriptAction->m_nParam == 1)
  1710. pSpeakList[i].bNeedConfirmNotify = TRUE;
  1711. pSpeakList[i].nInforLen = TEncodeText(pSpeakList[i].sInformation, strlen(pSpeakList[i].sInformation));
  1712. nCount++;
  1713. break;
  1714. }
  1715. nCount ++;
  1716. }
  1717. if (pBackupAnswer)
  1718. {
  1719. delete []pBackupAnswer;
  1720. pBackupAnswer = NULL;
  1721. }
  1722. g_bUISpeakActiveWithServer = pScriptAction->m_bParam2;
  1723. CoreDataChanged(GDCNI_SPEAK_WORDS,(unsigned int)pSpeakList, nCount);
  1724. if (pSpeakList)
  1725. {
  1726. delete pSpeakList;
  1727. pSpeakList = NULL;
  1728. }
  1729. }
  1730. break;
  1731. case UI_NOTEINFO:
  1732. {
  1733. if (pScriptAction->m_nBufferLen <= 0) 
  1734. break;
  1735. KMissionRecord Record;
  1736. //主信息为字符串
  1737. if (pScriptAction->m_bParam1 == 0)
  1738. {
  1739. g_StrCpyLen(Record.sContent, pScriptAction->m_pContent,  pScriptAction->m_nBufferLen - sizeof(int) - 1);
  1740. Record.uValue = *(unsigned int*) (pScriptAction->m_pContent + pScriptAction->m_nBufferLen - sizeof(int));
  1741. }
  1742. else
  1743. {
  1744. g_GetStringRes(*(int *)pScriptAction->m_pContent, Record.sContent ,sizeof(Record.sContent));
  1745. Record.uValue = *(unsigned int* ) (Record.sContent + sizeof(int));
  1746. }
  1747. Record.nContentLen = TEncodeText(Record.sContent, strlen(Record.sContent));
  1748. CoreDataChanged(GDCNI_MISSION_RECORD, (unsigned long)&Record, 0);
  1749. }
  1750. break;
  1751. case UI_MSGINFO:
  1752. {
  1753. if (pScriptAction->m_nBufferLen <= 0) 
  1754. break;
  1755. char strContent[1024];
  1756. //主信息为字符串
  1757. if (pScriptAction->m_bParam1 == 0)
  1758. {
  1759. g_StrCpyLen(strContent, pScriptAction->m_pContent,  pScriptAction->m_nBufferLen + 1);
  1760. }
  1761. else
  1762. {
  1763. g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
  1764. }
  1765. KSystemMessage sMsg;
  1766. sMsg.eType = SMT_PLAYER;
  1767. sMsg.byConfirmType = SMCT_MSG_BOX;
  1768. sMsg.byPriority = 0;
  1769. sMsg.byParamSize = 0;
  1770. g_StrCpyLen(sMsg.szMessage, strContent, sizeof(sMsg.szMessage));
  1771. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1772. //CoreDataChanged(GDCNI_MISSION_RECORD, (unsigned int)strContent, strlen(strContent));
  1773. }break;
  1774. case UI_NEWSINFO:
  1775. {
  1776. if (pScriptAction->m_nBufferLen <= 0) 
  1777. break;
  1778. switch(pScriptAction->m_bOptionNum) //OPtionNum代表是哪一种News类型
  1779. {
  1780. case NEWSMESSAGE_NORMAL:
  1781. {
  1782. KNewsMessage News;
  1783. News.nType = NEWSMESSAGE_NORMAL;
  1784. char strContent[1024];
  1785. //主信息为字符串
  1786. if (pScriptAction->m_bParam1 == 0)
  1787. {
  1788. g_StrCpyLen(strContent, pScriptAction->m_pContent,  pScriptAction->m_nBufferLen + 1);
  1789. }
  1790. else
  1791. {
  1792. g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
  1793. }
  1794. g_StrCpyLen(News.sMsg,  strContent, sizeof(News.sMsg));
  1795. News.nMsgLen = TEncodeText(News.sMsg, strlen(News.sMsg));
  1796. CoreDataChanged(GDCNI_NEWS_MESSAGE, (unsigned int)&News, 0);
  1797. }
  1798. break;
  1799. //STRING|STRINGID + TIME(INT)
  1800. case NEWSMESSAGE_COUNTING:
  1801. {
  1802. KNewsMessage News;
  1803. News.nType = pScriptAction->m_bOptionNum;
  1804. char strContent[1024];
  1805. int nTime = 0;
  1806. //主信息为字符串
  1807. if (pScriptAction->m_bParam1 == 0)
  1808. {
  1809. g_StrCpyLen(strContent, pScriptAction->m_pContent,  pScriptAction->m_nBufferLen - sizeof(int) + 1);
  1810. }
  1811. else
  1812. {
  1813. g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
  1814. }
  1815. g_StrCpyLen(News.sMsg,  strContent, sizeof(News.sMsg));
  1816. News.nMsgLen = TEncodeText(News.sMsg, strlen(News.sMsg));
  1817. SYSTEMTIME systime;
  1818. memset(&systime, 0, sizeof(SYSTEMTIME));
  1819. systime.wSecond = *(int *)((pScriptAction->m_pContent + pScriptAction->m_nBufferLen - sizeof(int)));
  1820. CoreDataChanged(GDCNI_NEWS_MESSAGE, (unsigned int)&News, (unsigned int)&systime);
  1821. }break;
  1822. case NEWSMESSAGE_TIMEEND:
  1823. {
  1824. KNewsMessage News;
  1825. News.nType = pScriptAction->m_bOptionNum;
  1826. char strContent[1024];
  1827. int nTime = 0;
  1828. //主信息为字符串
  1829. if (pScriptAction->m_bParam1 == 0)
  1830. {
  1831. g_StrCpyLen(strContent, pScriptAction->m_pContent,  pScriptAction->m_nBufferLen - sizeof(SYSTEMTIME) + 1);
  1832. }
  1833. else
  1834. {
  1835. g_GetStringRes(*(int *)pScriptAction->m_pContent, strContent ,sizeof(strContent));
  1836. }
  1837. g_StrCpyLen(News.sMsg,  strContent, sizeof(News.sMsg));
  1838. News.nMsgLen = TEncodeText(News.sMsg, strlen(News.sMsg));
  1839. SYSTEMTIME systime;
  1840. systime = *(SYSTEMTIME*)((pScriptAction->m_pContent + pScriptAction->m_nBufferLen - sizeof(SYSTEMTIME)));
  1841. CoreDataChanged(GDCNI_NEWS_MESSAGE, (unsigned int)&News, (unsigned int)&systime);
  1842. }break;
  1843. }
  1844. }break;
  1845. case UI_PLAYMUSIC:
  1846. {
  1847. char szMusicFile[MAX_PATH];
  1848. memcpy(szMusicFile, pScriptAction->m_pContent, pScriptAction->m_nBufferLen);
  1849. szMusicFile[pScriptAction->m_nBufferLen] = 0;
  1850. g_SubWorldSet.m_cMusic.ScriptPlay(szMusicFile);
  1851. }break;
  1852. case UI_OPENTONGUI:
  1853. {
  1854. Player[CLIENT_PLAYER_INDEX].m_cTong.OpenCreateInterface();
  1855. break;
  1856. }
  1857. }
  1858. } break;
  1859. case SCRIPTACTION_EXESCRIPT://要求客户端调用某个脚本
  1860. {
  1861. if (pScriptAction->m_nBufferLen <= 0 ) break;
  1862. char szScriptInfo[1000];
  1863. g_StrCpyLen(szScriptInfo, pScriptAction->m_pContent,pScriptAction->m_nBufferLen + 1);
  1864. char * pDivPos = strstr(szScriptInfo, "/");
  1865. if (pDivPos) *pDivPos++ = 0; 
  1866. if (pDivPos)
  1867. ExecuteScript(szScriptInfo, "OnCall", pDivPos);
  1868. else
  1869. ExecuteScript(szScriptInfo, "OnCall", "");
  1870. }
  1871. break;
  1872. }
  1873. }
  1874. #endif
  1875. #ifdef _SERVER
  1876. int KPlayer::AddTempTaskValue(void* pData)
  1877. {
  1878. memcpy(m_cTask.nClear, pData, sizeof(int) * MAX_TEMP_TASK);
  1879. return 1;
  1880. }
  1881. //客户端请求与某个Npc对话
  1882. //服务器版本
  1883. void KPlayer::DialogNpc(BYTE * pProtocol)
  1884. {
  1885. //if (m_nAvailableAnswerNum > 0) return ;
  1886. PLAYER_DIALOG_NPC_COMMAND * pDialogNpc = (PLAYER_DIALOG_NPC_COMMAND*) pProtocol;
  1887. int nIdx = 0;
  1888. if (pDialogNpc->nNpcId < 0) return;
  1889. nIdx = FindAroundNpc(pDialogNpc->nNpcId);//NpcSet.SearchID(pDialogNpc->nNpcId);
  1890. if (nIdx > 0) 
  1891. {
  1892. int distance = NpcSet.GetDistance(nIdx, m_nIndex);
  1893. // 小于对话半径就开始对话
  1894. if ((Npc[nIdx].m_Kind == kind_dialoger) ||
  1895. (NpcSet.GetRelation(m_nIndex, nIdx) == relation_none))
  1896. {
  1897. if (distance <= Npc[nIdx].m_DialogRadius * 2) // 放大server对话半径
  1898. {
  1899. if (Npc[nIdx].ActionScript[0])
  1900. {
  1901. ExecuteScript(Npc[nIdx].m_ActionScriptID, "main", "");
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. #endif
  1908. #ifndef _SERVER
  1909. void KPlayer::s2cTradeChangeState(BYTE* pMsg)
  1910. {
  1911. TRADE_CHANGE_STATE_SYNC *pTrade = (TRADE_CHANGE_STATE_SYNC*)pMsg;
  1912. switch (m_cMenuState.m_nState)
  1913. {
  1914. case PLAYER_MENU_STATE_NORMAL: // 当前客户端 NORMAL
  1915. case PLAYER_MENU_STATE_TRADEOPEN: // 当前客户端 TRADEOPEN
  1916. if (pTrade->m_btState == 0)
  1917. {
  1918. m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
  1919. CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
  1920. }
  1921. else if (pTrade->m_btState == 1)
  1922. {
  1923. m_cMenuState.SetState(PLAYER_MENU_STATE_TRADEOPEN);
  1924. CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
  1925. }
  1926. else if (pTrade->m_btState == 2)
  1927. {
  1928. m_cMenuState.SetState(PLAYER_MENU_STATE_TRADING);
  1929. m_cTrade.StartTrade(pTrade->m_dwNpcID);
  1930. m_ItemList.StartTrade();
  1931. // 通知界面进入交易界面
  1932. KUiPlayerItem sTradePlayer;
  1933. int nIdx;
  1934. nIdx = NpcSet.SearchID(pTrade->m_dwNpcID);
  1935. if (nIdx > 0)
  1936. strcpy(sTradePlayer.Name, Npc[nIdx].Name);
  1937. else
  1938. sTradePlayer.Name[0] = 0;
  1939. sTradePlayer.nIndex = 0;
  1940. sTradePlayer.uId = 0;
  1941. sTradePlayer.nData = 0;
  1942. CoreDataChanged(GDCNI_TRADE_START, (unsigned int)(&sTradePlayer), 0);
  1943. if (Npc[m_nIndex].m_Doing == do_sit)
  1944. {
  1945. Npc[m_nIndex].SendCommand(do_stand);
  1946. }
  1947. }
  1948. break;
  1949. case PLAYER_MENU_STATE_TEAMOPEN: // 当前客户端 TEAMOPEN
  1950. g_Team[0].SetTeamClose();
  1951. if (pTrade->m_btState == 0)
  1952. {
  1953. m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
  1954. CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
  1955. }
  1956. else if (pTrade->m_btState == 1)
  1957. {
  1958. m_cMenuState.SetState(PLAYER_MENU_STATE_TRADEOPEN);
  1959. CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
  1960. }
  1961. else if (pTrade->m_btState == 2)
  1962. {
  1963. m_cMenuState.SetState(PLAYER_MENU_STATE_TRADING);
  1964. m_cTrade.StartTrade(pTrade->m_dwNpcID);
  1965. m_ItemList.StartTrade();
  1966. // 通知界面进入交易界面
  1967. KUiPlayerItem sTradePlayer;
  1968. int nIdx;
  1969. nIdx = NpcSet.SearchID(pTrade->m_dwNpcID);
  1970. if (nIdx > 0)
  1971. strcpy(sTradePlayer.Name, Npc[nIdx].Name);
  1972. else
  1973. sTradePlayer.Name[0] = 0;
  1974. sTradePlayer.Name[0] = 0;
  1975. sTradePlayer.nIndex = 0;
  1976. sTradePlayer.uId = 0;
  1977. sTradePlayer.nData = 0;
  1978. CoreDataChanged(GDCNI_TRADE_START, (unsigned int)(&sTradePlayer), 0);
  1979. if (Npc[m_nIndex].m_Doing == do_sit)
  1980. {
  1981. Npc[m_nIndex].SendCommand(do_stand);
  1982. }
  1983. }
  1984. break;
  1985. case PLAYER_MENU_STATE_TRADING: // 当前客户端 TRADING
  1986. // 当客户端处于 TRADING 时,不应该收到此协议
  1987. if (pTrade->m_btState == 0)
  1988. {
  1989. m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
  1990. CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
  1991. }
  1992. else if (pTrade->m_btState == 1)
  1993. {
  1994. m_cMenuState.SetState(PLAYER_MENU_STATE_TRADEOPEN);
  1995. CoreDataChanged(GDCNI_TRADE_OPER_DATA, 0, 0);
  1996. }
  1997. else if (pTrade->m_btState == 2) // 客户端此时不应该在这个状态,客户端已出错
  1998. {
  1999. m_cMenuState.m_nState = PLAYER_MENU_STATE_TRADING;
  2000. m_cMenuState.m_nTradeDest = pTrade->m_dwNpcID;
  2001. m_cMenuState.m_nTradeState = 0;
  2002. m_cMenuState.m_nTradeDestState = 0;
  2003. this->m_ItemList.RecoverTrade();
  2004. this->m_ItemList.BackupTrade();
  2005. this->m_ItemList.ClearRoom(room_trade);
  2006. this->m_ItemList.ClearRoom(room_trade1);
  2007. // 通知界面进入交易界面
  2008. KUiPlayerItem sTradePlayer;
  2009. int nIdx;
  2010. nIdx = NpcSet.SearchID(pTrade->m_dwNpcID);
  2011. if (nIdx > 0)
  2012. strcpy(sTradePlayer.Name, Npc[nIdx].Name);
  2013. else
  2014. sTradePlayer.Name[0] = 0;
  2015. sTradePlayer.Name[0] = 0;
  2016. sTradePlayer.nIndex = 0;
  2017. sTradePlayer.uId = 0;
  2018. sTradePlayer.nData = 0;
  2019. CoreDataChanged(GDCNI_TRADE_START, (unsigned int)(&sTradePlayer), 0);
  2020. if (Npc[m_nIndex].m_Doing == do_sit)
  2021. {
  2022. Npc[m_nIndex].SendCommand(do_stand);
  2023. }
  2024. }
  2025. break;
  2026. }
  2027. }
  2028. #endif
  2029. #ifndef _SERVER
  2030. void KPlayer::s2cLevelUp(BYTE* pMsg)
  2031. {
  2032. PLAYER_LEVEL_UP_SYNC *pLevel = (PLAYER_LEVEL_UP_SYNC*)pMsg;
  2033. if ((DWORD)Npc[m_nIndex].m_Level < (DWORD)pLevel->m_btLevel && m_nExp < PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level))
  2034. {
  2035. KSystemMessage sMsg;
  2036. sprintf(sMsg.szMessage, MSG_GET_EXP, PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level) - m_nExp);
  2037. sMsg.eType = SMT_NORMAL;
  2038. sMsg.byConfirmType = SMCT_NONE;
  2039. sMsg.byPriority = 0;
  2040. sMsg.byParamSize = 0;
  2041. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2042. }
  2043. m_nExp = 0;
  2044. Npc[m_nIndex].m_Level = (DWORD)pLevel->m_btLevel;
  2045. m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level);
  2046. // -------------------------- 等级增加时各项属性同步 ----------------------
  2047. // 同步未分配属性点
  2048. if (pLevel->m_nAttributePoint > m_nAttributePoint)
  2049. {
  2050. KSystemMessage Msg;
  2051. sprintf(Msg.szMessage, MSG_GET_ATTRIBUTE_POINT, pLevel->m_nAttributePoint - m_nAttributePoint);
  2052. Msg.eType = SMT_PLAYER;
  2053. Msg.byConfirmType = SMCT_UI_ATTRIBUTE;
  2054. Msg.byPriority = 3;
  2055. Msg.byParamSize = 0;
  2056. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
  2057. }
  2058. m_nAttributePoint = pLevel->m_nAttributePoint;
  2059. // 同步未分配技能点
  2060. if (m_nSkillPoint < pLevel->m_nSkillPoint)
  2061. {
  2062. KSystemMessage Msg;
  2063. sprintf(Msg.szMessage, MSG_GET_SKILL_POINT, pLevel->m_nSkillPoint - m_nSkillPoint);
  2064. Msg.eType = SMT_PLAYER;
  2065. Msg.byConfirmType = SMCT_UI_SKILLS;
  2066. Msg.byPriority = 3;
  2067. Msg.byParamSize = 0;
  2068. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
  2069. }
  2070. m_nSkillPoint = pLevel->m_nSkillPoint;
  2071. // 处理生命、体力、内力值(影响基本生命、体力、内力最大值的因素:等级、属性点,影响当前生命最大值的因素:装备、技能、药物(临时))
  2072. Npc[m_nIndex].m_LifeMax = pLevel->m_nBaseLifeMax;
  2073. Npc[m_nIndex].m_StaminaMax = pLevel->m_nBaseStaminaMax;
  2074. Npc[m_nIndex].m_ManaMax = pLevel->m_nBaseManaMax;
  2075. // Npc[m_nIndex].ResetLifeReplenish();
  2076. Npc[m_nIndex].m_CurrentLifeMax = Npc[m_nIndex].m_LifeMax;
  2077. Npc[m_nIndex].m_CurrentStaminaMax = Npc[m_nIndex].m_StaminaMax;
  2078. Npc[m_nIndex].m_CurrentManaMax = Npc[m_nIndex].m_ManaMax;
  2079. // 处理各种抗性的变化 火、冰、毒、电、物理
  2080. Npc[m_nIndex].m_FireResist = PlayerSet.m_cLevelAdd.GetFireResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2081. Npc[m_nIndex].m_CurrentFireResist = Npc[m_nIndex].m_FireResist;
  2082. Npc[m_nIndex].m_ColdResist = PlayerSet.m_cLevelAdd.GetColdResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2083. Npc[m_nIndex].m_CurrentColdResist = Npc[m_nIndex].m_ColdResist;
  2084. Npc[m_nIndex].m_PoisonResist = PlayerSet.m_cLevelAdd.GetPoisonResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2085. Npc[m_nIndex].m_CurrentPoisonResist = Npc[m_nIndex].m_PoisonResist;
  2086. Npc[m_nIndex].m_LightResist = PlayerSet.m_cLevelAdd.GetLightResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2087. Npc[m_nIndex].m_CurrentLightResist = Npc[m_nIndex].m_LightResist;
  2088. Npc[m_nIndex].m_PhysicsResist = PlayerSet.m_cLevelAdd.GetPhysicsResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2089. Npc[m_nIndex].m_CurrentPhysicsResist = Npc[m_nIndex].m_PhysicsResist;
  2090. Npc[m_nIndex].m_FireResistMax = BASE_FIRE_RESIST_MAX;
  2091. Npc[m_nIndex].m_ColdResistMax = BASE_COLD_RESIST_MAX;
  2092. Npc[m_nIndex].m_PoisonResistMax = BASE_POISON_RESIST_MAX;
  2093. Npc[m_nIndex].m_LightResistMax = BASE_LIGHT_RESIST_MAX;
  2094. Npc[m_nIndex].m_PhysicsResistMax = BASE_PHYSICS_RESIST_MAX;
  2095. Npc[m_nIndex].m_CurrentFireResistMax = Npc[m_nIndex].m_FireResistMax;
  2096. Npc[m_nIndex].m_CurrentColdResistMax = Npc[m_nIndex].m_ColdResistMax;
  2097. Npc[m_nIndex].m_CurrentPoisonResistMax = Npc[m_nIndex].m_PoisonResistMax;
  2098. Npc[m_nIndex].m_CurrentLightResistMax = Npc[m_nIndex].m_LightResistMax;
  2099. Npc[m_nIndex].m_CurrentPhysicsResistMax = Npc[m_nIndex].m_PhysicsResistMax;
  2100. int nOldCurCamp = Npc[m_nIndex].m_CurrentCamp;
  2101. // 根据装备、技能信息更新当前数据
  2102. this->UpdataCurData();
  2103. SetNpcPhysicsDamage();
  2104. Npc[m_nIndex].m_CurrentCamp = nOldCurCamp;
  2105. // 生命、体力、内力值加满
  2106. Npc[m_nIndex].m_CurrentLife = Npc[m_nIndex].m_CurrentLifeMax;
  2107. Npc[m_nIndex].m_CurrentStamina = Npc[m_nIndex].m_CurrentStaminaMax;
  2108. Npc[m_nIndex].m_CurrentMana = Npc[m_nIndex].m_CurrentManaMax;
  2109. // 客户端队伍中自己的等级加一
  2110. if (this->m_cTeam.m_nFlag)
  2111. {
  2112. if (m_cTeam.m_nFigure == TEAM_CAPTAIN)
  2113. {
  2114. g_Team[0].m_nMemLevel[0] = Npc[m_nIndex].m_Level;
  2115. }
  2116. else
  2117. {
  2118. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  2119. {
  2120. if ((DWORD)g_Team[0].m_nMember[i] == Npc[m_nIndex].m_dwID)
  2121. {
  2122. g_Team[0].m_nMemLevel[i] = Npc[m_nIndex].m_Level;
  2123. break;
  2124. }
  2125. }
  2126. }
  2127. }
  2128. KSystemMessage Msg;
  2129. Msg.byConfirmType = SMCT_CLICK;
  2130. Msg.byParamSize = 0;
  2131. Msg.byPriority = 1;
  2132. Msg.eType = SMT_PLAYER;
  2133. sprintf(Msg.szMessage, MSG_LEVEL_UP, Npc[m_nIndex].m_Level);
  2134. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
  2135. Npc[this->m_nIndex].SetInstantSpr(enumINSTANT_STATE_LEVELUP);
  2136. }
  2137. #endif
  2138. #ifndef _SERVER
  2139. void KPlayer::s2cGetCurAttribute(BYTE* pMsg)
  2140. {
  2141. PLAYER_ATTRIBUTE_SYNC *pAttribute = (PLAYER_ATTRIBUTE_SYNC*)pMsg;
  2142. m_nAttributePoint = pAttribute->m_nLeavePoint;
  2143. int nData;
  2144. switch (pAttribute->m_btAttribute)
  2145. {
  2146. case ATTRIBUTE_STRENGTH:
  2147. nData = pAttribute->m_nBasePoint - m_nStrength;
  2148. m_nStrength = pAttribute->m_nBasePoint;
  2149. m_nCurStrength = pAttribute->m_nCurPoint;
  2150. UpdataCurData();
  2151. SetNpcPhysicsDamage();
  2152. break;
  2153. case ATTRIBUTE_DEXTERITY:
  2154. nData = pAttribute->m_nBasePoint - m_nDexterity;
  2155. m_nDexterity = pAttribute->m_nBasePoint;
  2156. SetNpcAttackRating();
  2157. SetNpcDefence();
  2158. UpdataCurData();
  2159. SetNpcPhysicsDamage();
  2160. break;
  2161. case ATTRIBUTE_VITALITY:
  2162. nData = pAttribute->m_nBasePoint - m_nVitality;
  2163. m_nVitality = pAttribute->m_nBasePoint;
  2164. Npc[m_nIndex].AddBaseLifeMax(PlayerSet.m_cLevelAdd.GetLifePerVitality(Npc[m_nIndex].m_Series) * nData);
  2165. Npc[m_nIndex].AddBaseStaminaMax(PlayerSet.m_cLevelAdd.GetStaminaPerVitality(Npc[m_nIndex].m_Series) * nData);
  2166. UpdataCurData();
  2167. break;
  2168. case ATTRIBUTE_ENGERGY:
  2169. nData = pAttribute->m_nBasePoint - m_nEngergy;
  2170. m_nEngergy = pAttribute->m_nBasePoint;
  2171. Npc[m_nIndex].AddBaseManaMax(PlayerSet.m_cLevelAdd.GetManaPerEnergy(Npc[m_nIndex].m_Series) * nData);
  2172. UpdataCurData();
  2173. break;
  2174. }
  2175. CoreDataChanged(GDCNI_PLAYER_RT_ATTRIBUTE, 0, 0);
  2176. }
  2177. #endif
  2178. #ifndef _SERVER
  2179. void KPlayer::s2cSetExp(int nExp)
  2180. {
  2181. if (nExp > m_nExp)
  2182. {
  2183. KSystemMessage sMsg;
  2184. sprintf(sMsg.szMessage, MSG_GET_EXP, nExp - m_nExp);
  2185. sMsg.eType = SMT_NORMAL;
  2186. sMsg.byConfirmType = SMCT_NONE;
  2187. sMsg.byPriority = 0;
  2188. sMsg.byParamSize = 0;
  2189. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2190. }
  2191. else if (nExp < m_nExp)
  2192. {
  2193. KSystemMessage sMsg;
  2194. sprintf(sMsg.szMessage, MSG_DEC_EXP, m_nExp - nExp);
  2195. sMsg.eType = SMT_NORMAL;
  2196. sMsg.byConfirmType = SMCT_NONE;
  2197. sMsg.byPriority = 0;
  2198. sMsg.byParamSize = 0;
  2199. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2200. }
  2201. this->m_nExp = nExp;
  2202. }
  2203. #endif
  2204. #ifndef _SERVER
  2205. void KPlayer::s2cSyncMoney(BYTE* pMsg)
  2206. {
  2207. PLAYER_MONEY_SYNC *pMoney = (PLAYER_MONEY_SYNC*)pMsg;
  2208. if ( CheckTrading() )
  2209. {
  2210. if (pMoney->m_nMoney1 >= pMoney->m_nMoney3)
  2211. {
  2212. m_ItemList.SetMoney(pMoney->m_nMoney1 - pMoney->m_nMoney3, pMoney->m_nMoney2, pMoney->m_nMoney3);
  2213. }
  2214. else
  2215. {
  2216. m_ItemList.SetMoney(0, pMoney->m_nMoney2 + pMoney->m_nMoney1 - pMoney->m_nMoney3, pMoney->m_nMoney3);
  2217. }
  2218. m_cTrade.m_nTradeState = 0;
  2219. m_cTrade.m_nTradeDestState = 0;
  2220. m_cTrade.m_nBackEquipMoney = pMoney->m_nMoney1;
  2221. m_cTrade.m_nBackRepositoryMoney = pMoney->m_nMoney2;
  2222. }
  2223. else
  2224. {
  2225. // 捡钱一定是到room_equipment
  2226. int nMoney1 = m_ItemList.GetMoney(room_equipment);
  2227. if (pMoney->m_nMoney1 - nMoney1 > 0)
  2228. {
  2229. KSystemMessage sMsg;
  2230. sMsg.eType = SMT_NORMAL;
  2231. sMsg.byConfirmType = SMCT_NONE;
  2232. sMsg.byPriority = 0;
  2233. sMsg.byParamSize = 0;
  2234. sprintf(sMsg.szMessage, MSG_EARN_MONEY, pMoney->m_nMoney1 - nMoney1);
  2235. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2236. }
  2237. m_ItemList.SetMoney(pMoney->m_nMoney1, pMoney->m_nMoney2, pMoney->m_nMoney3);
  2238. }
  2239. }
  2240. #endif
  2241. #ifndef _SERVER
  2242. //---------------------------------------------------------------------
  2243. // 功能:收到服务器通知有人申请交易
  2244. //---------------------------------------------------------------------
  2245. void KPlayer::s2cTradeApplyStart(BYTE* pMsg)
  2246. {
  2247. if (!pMsg)
  2248. return;
  2249. TRADE_APPLY_START_SYNC *pApply = (TRADE_APPLY_START_SYNC*)pMsg;
  2250. int nNpcIdx;
  2251. nNpcIdx = NpcSet.SearchID(pApply->m_dwNpcId);
  2252. if (nNpcIdx == 0)
  2253. return;
  2254. KSystemMessage sMsg;
  2255. KUiPlayerItem sPlayer;
  2256. strcpy(sPlayer.Name, Npc[nNpcIdx].Name);
  2257. sPlayer.nIndex = pApply->m_nDestIdx;
  2258. sPlayer.uId = pApply->m_dwNpcId;
  2259. sPlayer.nData = 0;
  2260. sprintf(sMsg.szMessage, MSG_TRADE_GET_APPLY, Npc[nNpcIdx].Name);
  2261. sMsg.eType = SMT_SYSTEM;
  2262. sMsg.byConfirmType = SMCT_UI_TRADE;
  2263. sMsg.byPriority = 3;
  2264. sMsg.byParamSize = sizeof(KUiPlayerItem);
  2265. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&sPlayer);
  2266. }
  2267. #endif
  2268. #ifndef _SERVER
  2269. void KPlayer::s2cTradeMoneySync(BYTE* pMsg)
  2270. {
  2271. TRADE_MONEY_SYNC *pMoney = (TRADE_MONEY_SYNC*)pMsg;
  2272. m_ItemList.SetRoomMoney(room_trade1, pMoney->m_nMoney);
  2273. // 通知界面
  2274. KUiObjAtRegion sMoney;
  2275. sMoney.Obj.uGenre = CGOG_MONEY;
  2276. sMoney.Obj.uId = pMoney->m_nMoney;
  2277. CoreDataChanged(GDCNI_TRADE_DESIRE_ITEM, (unsigned int)&sMoney, 0);
  2278. }
  2279. #endif
  2280. #ifndef _SERVER
  2281. //---------------------------------------------------------------------
  2282. // 功能:收到服务器通知交易完成或取消
  2283. //---------------------------------------------------------------------
  2284. void KPlayer::s2cTradeDecision(BYTE* pMsg)
  2285. {
  2286. TRADE_DECISION_SYNC *pSync = (TRADE_DECISION_SYNC*)pMsg;
  2287. if (pSync->m_btDecision == 1) // 完成交易
  2288. {
  2289. KSystemMessage sMsg;
  2290. sprintf(sMsg.szMessage, MSG_TRADE_SUCCESS, m_cTrade.m_szDestName);
  2291. sMsg.eType = SMT_NORMAL;
  2292. sMsg.byConfirmType = SMCT_NONE;
  2293. sMsg.byPriority = 0;
  2294. sMsg.byParamSize = 0;
  2295. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2296. // 交给ItemList.Remove来清除 modify by spe 03/06/14
  2297. //m_ItemList.ClearRoom(room_trade);
  2298. m_ItemList.RemoveAllInOneRoom(room_trade1);
  2299. //m_ItemList.ClearRoom(room_trade1);
  2300. m_ItemList.ClearRoom(room_tradeback);
  2301. this->m_cTrade.Release();
  2302. m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
  2303. // 通知界面交易结束
  2304. CoreDataChanged(GDCNI_TRADE_END, 0, 0);
  2305. m_ItemList.MenuSetMouseItem();
  2306. }
  2307. else if (pSync->m_btDecision == 0) // 取消交易
  2308. {
  2309. if ( !CheckTrading() )
  2310. return;
  2311. KSystemMessage sMsg;
  2312. sprintf(sMsg.szMessage, MSG_TRADE_FAIL, m_cTrade.m_szDestName);
  2313. sMsg.eType = SMT_NORMAL;
  2314. sMsg.byConfirmType = SMCT_NONE;
  2315. sMsg.byPriority = 0;
  2316. sMsg.byParamSize = 0;
  2317. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2318. // 取消交易的数据恢复
  2319. m_ItemList.RecoverTrade();
  2320. m_ItemList.SetMoney(m_cTrade.m_nBackEquipMoney, m_cTrade.m_nBackRepositoryMoney, 0);
  2321. m_ItemList.ClearRoom(room_trade);
  2322. m_ItemList.RemoveAllInOneRoom(room_trade1);
  2323. // m_ItemList.ClearRoom(room_trade1);
  2324. m_ItemList.ClearRoom(room_tradeback);
  2325. m_cTrade.Release();
  2326. m_cMenuState.SetState(PLAYER_MENU_STATE_NORMAL);
  2327. // 通知界面交易结束
  2328. CoreDataChanged(GDCNI_TRADE_END, 0, 0);
  2329. // 更新物品面版
  2330. CoreDataChanged(GDCNI_CONTAINER_OBJECT_CHANGED, UOC_ITEM_TAKE_WITH, 0);
  2331. m_ItemList.MenuSetMouseItem();
  2332. }
  2333. }
  2334. #endif
  2335. #ifndef _SERVER
  2336. void KPlayer::SyncCurPlayer(BYTE* pMsg)
  2337. {
  2338. m_ItemList.RemoveAll();
  2339. CURPLAYER_SYNC* PlaySync = (CURPLAYER_SYNC *)pMsg;
  2340. this->m_nIndex = NpcSet.SearchID(PlaySync->m_dwID);
  2341. this->m_dwID = g_FileName2Id(Npc[m_nIndex].Name); 
  2342. Npc[m_nIndex].m_Kind = kind_player;
  2343. Npc[m_nIndex].m_Level = (DWORD)PlaySync->m_btLevel;
  2344. Npc[m_nIndex].m_nSex = PlaySync->m_btSex;
  2345. Npc[m_nIndex].m_Series  = PlaySync->m_btSeries;
  2346. Npc[m_nIndex].SetPlayerIdx(CLIENT_PLAYER_INDEX);
  2347. m_nAttributePoint = PlaySync->m_wAttributePoint;
  2348. m_nSkillPoint = PlaySync->m_wSkillPoint;
  2349. m_nStrength = PlaySync->m_wStrength;
  2350. m_nDexterity = PlaySync->m_wDexterity;
  2351. m_nVitality = PlaySync->m_wVitality;
  2352. m_nEngergy = PlaySync->m_wEngergy;
  2353. m_nLucky = PlaySync->m_wLucky;
  2354. m_nCurStrength = m_nStrength;
  2355. m_nCurDexterity = m_nDexterity;
  2356. m_nCurVitality = m_nVitality;
  2357. m_nCurEngergy = m_nEngergy;
  2358. m_nCurLucky = m_nLucky;
  2359. SetFirstDamage();
  2360. SetBaseAttackRating();
  2361. SetBaseDefence();
  2362. Npc[m_nIndex].m_ActionScriptID = 0;
  2363. Npc[m_nIndex].m_TrapScriptID = 0;
  2364. m_nExp = PlaySync->m_nExp;
  2365. m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(PlaySync->m_btLevel);
  2366. m_dwLeadExp = PlaySync->m_dwLeadExp;
  2367. m_dwLeadLevel = PlayerSet.m_cLeadExp.GetLevel(m_dwLeadExp);
  2368. m_dwNextLevelLeadExp = PlayerSet.m_cLeadExp.GetLevelExp(m_dwLeadLevel);
  2369. m_cFaction.m_nCurFaction = (char)PlaySync->m_btCurFaction;
  2370. m_cFaction.m_nFirstAddFaction = (char)PlaySync->m_btFirstFaction;
  2371. m_cFaction.m_nAddTimes = PlaySync->m_nFactionAddTimes;
  2372. m_nWorldStat = (int)PlaySync->m_wWorldStat;
  2373. m_nSectStat = (int)PlaySync->m_wSectStat;
  2374. m_ItemList.Init(CLIENT_PLAYER_INDEX);
  2375. m_ItemList.SetMoney(PlaySync->m_nMoney1, PlaySync->m_nMoney2, 0);
  2376. Npc[m_nIndex].m_LifeMax = PlaySync->m_wLifeMax;
  2377. Npc[m_nIndex].m_ManaMax = PlaySync->m_wManaMax;
  2378. Npc[m_nIndex].m_StaminaMax = PlaySync->m_wStaminaMax;
  2379. Npc[m_nIndex].m_LifeReplenish = PLAYER_LIFE_REPLENISH;
  2380. Npc[m_nIndex].m_ManaReplenish = PLAYER_MANA_REPLENISH;
  2381. Npc[m_nIndex].m_StaminaGain = PLAYER_STAMINA_GAIN;
  2382. Npc[m_nIndex].m_StaminaLoss = PLAYER_STAMINA_LOSS;
  2383. SetBaseResistData();
  2384. SetBaseSpeedAndRadius();
  2385. Npc[m_nIndex].RestoreNpcBaseInfo();
  2386. m_BuyInfo.Clear();
  2387. m_cMenuState.Release();
  2388. m_cChat.Release();
  2389. memset(m_szTaskAnswerFun, 0, sizeof(m_szTaskAnswerFun));
  2390. m_nAvailableAnswerNum = 0;
  2391. Npc[m_nIndex].m_Experience = 0;
  2392. memset(Npc[m_nIndex].m_szChatBuffer, 0, sizeof(Npc[m_nIndex].m_szChatBuffer));
  2393. Npc[m_nIndex].m_nCurChatTime = 0;
  2394. m_RunStatus = 1;
  2395. m_nLeftSkillID = 0;
  2396. m_nLeftSkillLevel = 0;
  2397. m_nRightSkillID = 0;
  2398. m_nRightSkillLevel = 0;
  2399. m_nPeapleIdx = 0;
  2400. m_nObjectIdx = 0;
  2401. m_MouseDown[0] = 0;
  2402. m_MouseDown[1] = 0;
  2403. Npc[m_nIndex].m_SyncSignal = 0;
  2404. //Npc[m_nIndex].RestoreLiveData();
  2405. // SubWorld[0].AddPlayer(Npc[m_nIndex].m_RegionIndex, 0);//m_Region[Npc[m_nIndex].m_RegionIndex].AddPlayer(0);// m_WorldMessage.Send(GWM_PLAYER_ADD, Npc[m_nIndex].m_RegionIndex, 0);
  2406. }
  2407. #endif
  2408. BOOL KPlayer::CheckTrading()
  2409. {
  2410. return (m_cMenuState.m_nState == PLAYER_MENU_STATE_TRADING);
  2411. }
  2412. void KPlayer::SetFirstDamage()
  2413. {
  2414. int nDamageBase;
  2415. nDamageBase = m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE + 1;
  2416. Npc[m_nIndex].m_PhysicsDamage.nValue[0] = nDamageBase;
  2417. Npc[m_nIndex].m_PhysicsDamage.nValue[2] = nDamageBase;
  2418. Npc[m_nIndex].m_PhysicsDamage.nValue[1] = 0;
  2419. Npc[m_nIndex].m_CurrentFireDamage.nValue[0] = 0;
  2420. Npc[m_nIndex].m_CurrentFireDamage.nValue[1] = 0;
  2421. Npc[m_nIndex].m_CurrentFireDamage.nValue[2] = 0;
  2422. Npc[m_nIndex].m_CurrentColdDamage.nValue[0] = 0;
  2423. Npc[m_nIndex].m_CurrentColdDamage.nValue[1] = 0;
  2424. Npc[m_nIndex].m_CurrentColdDamage.nValue[2] = 0;
  2425. Npc[m_nIndex].m_CurrentLightDamage.nValue[0] = 0;
  2426. Npc[m_nIndex].m_CurrentLightDamage.nValue[1] = 0;
  2427. Npc[m_nIndex].m_CurrentLightDamage.nValue[2] = 0;
  2428. Npc[m_nIndex].m_CurrentPoisonDamage.nValue[0] = 0;
  2429. Npc[m_nIndex].m_CurrentPoisonDamage.nValue[1] = 0;
  2430. Npc[m_nIndex].m_CurrentPoisonDamage.nValue[2] = 0;
  2431. }
  2432. void KPlayer::SetBaseAttackRating()
  2433. {
  2434. Npc[m_nIndex].m_AttackRating = m_nDexterity * 4 - 28;
  2435. }
  2436. void KPlayer::SetBaseDefence()
  2437. {
  2438. Npc[m_nIndex].m_Defend = m_nDexterity >> 2;
  2439. }
  2440. void KPlayer::SetBaseResistData()
  2441. {
  2442. Npc[m_nIndex].m_FireResist = PlayerSet.m_cLevelAdd.GetFireResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2443. Npc[m_nIndex].m_ColdResist = PlayerSet.m_cLevelAdd.GetColdResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2444. Npc[m_nIndex].m_PoisonResist = PlayerSet.m_cLevelAdd.GetPoisonResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2445. Npc[m_nIndex].m_LightResist = PlayerSet.m_cLevelAdd.GetLightResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2446. Npc[m_nIndex].m_PhysicsResist = PlayerSet.m_cLevelAdd.GetPhysicsResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2447. Npc[m_nIndex].m_FireResistMax = BASE_FIRE_RESIST_MAX;
  2448. Npc[m_nIndex].m_ColdResistMax = BASE_COLD_RESIST_MAX;
  2449. Npc[m_nIndex].m_PoisonResistMax = BASE_POISON_RESIST_MAX;
  2450. Npc[m_nIndex].m_LightResistMax = BASE_LIGHT_RESIST_MAX;
  2451. Npc[m_nIndex].m_PhysicsResistMax = BASE_PHYSICS_RESIST_MAX;
  2452. }
  2453. void KPlayer::SetBaseSpeedAndRadius()
  2454. {
  2455. Npc[m_nIndex].m_WalkSpeed = BASE_WALK_SPEED;
  2456. Npc[m_nIndex].m_RunSpeed = BASE_RUN_SPEED;
  2457. Npc[m_nIndex].m_AttackSpeed = BASE_ATTACK_SPEED;
  2458. Npc[m_nIndex].m_CastSpeed = BASE_CAST_SPEED;
  2459. Npc[m_nIndex].m_VisionRadius = BASE_VISION_RADIUS;
  2460. Npc[m_nIndex].m_HitRecover = BASE_HIT_RECOVER;
  2461. }
  2462. #ifndef _SERVER
  2463. //客户端版本
  2464. void KPlayer::DialogNpc(int nIndex)
  2465. {
  2466. if (nIndex > 0 && Npc[nIndex].m_Index > 0)
  2467. {
  2468. if (Npc[nIndex].ActionScript[0])
  2469. {
  2470. ExecuteScript(Npc[nIndex].m_ActionScriptID,"main","");
  2471. }
  2472. else
  2473. {
  2474. PLAYER_DIALOG_NPC_COMMAND DialogNpcCmd;
  2475. DialogNpcCmd.nNpcId = Npc[nIndex].m_dwID;
  2476. DialogNpcCmd.ProtocolType = c2s_dialognpc;
  2477. if (g_pClient)
  2478. g_pClient->SendPackToServer(&DialogNpcCmd, sizeof(PLAYER_DIALOG_NPC_COMMAND));
  2479. }
  2480. }
  2481. }
  2482. #endif
  2483. #ifndef _SERVER
  2484. void KPlayer::CheckObject(int nIdx)
  2485. {
  2486. /* enum // 物件类型
  2487. {
  2488. Obj_Kind_MapObj = 0, // 地图物件,主要用于地图动画
  2489. Obj_Kind_Body, // npc 的尸体
  2490. Obj_Kind_Box, // 宝箱
  2491. Obj_Kind_Item, // 掉在地上的装备
  2492. Obj_Kind_Money, // 掉在地上的钱
  2493. Obj_Kind_LoopSound, // 循环音效
  2494. Obj_Kind_RandSound, // 随机音效
  2495. Obj_Kind_Light, // 光源(3D模式中发光的东西)
  2496. Obj_Kind_Door, // 门类
  2497. Obj_Kind_Trap, // 陷阱
  2498. Obj_Kind_Prop, // 小道具,可重生
  2499. Obj_Kind_Num, // 物件的种类数
  2500. };*/
  2501. switch(Object[nIdx].m_nKind)
  2502. {
  2503. case Obj_Kind_Item:
  2504. case Obj_Kind_Money:
  2505. PickUpObj(nIdx);
  2506. Npc[m_nIndex].m_nObjectIdx = 0;
  2507. break;
  2508. case Obj_Kind_Box:
  2509. case Obj_Kind_Door:
  2510. case Obj_Kind_Trap:
  2511. case Obj_Kind_Prop:
  2512. this->ObjMouseClick(nIdx);
  2513. Npc[m_nIndex].m_nObjectIdx = 0;
  2514. break;
  2515. default:
  2516. break;
  2517. }
  2518. m_nObjectIdx = 0;
  2519. m_nPickObjectIdx = 0;
  2520. }
  2521. #endif
  2522. #ifndef _SERVER
  2523. void KPlayer::DrawSelectInfo()
  2524. {
  2525. if (m_nIndex <= 0)
  2526. return;
  2527. if (m_nPeapleIdx)
  2528. {
  2529. // Npc[m_nPeapleIdx].DrawBorder();
  2530. if (Npc[m_nPeapleIdx].m_Kind == kind_player)
  2531. {
  2532. if (!NpcSet.CheckShowName())
  2533. {
  2534. Npc[m_nPeapleIdx].PaintInfo(Npc[m_nPeapleIdx].GetNpcPate(), true);
  2535. }
  2536. }
  2537. else if (Npc[m_nPeapleIdx].m_Kind == kind_dialoger)
  2538. {
  2539. if (!NpcSet.CheckShowName())
  2540. {
  2541. Npc[m_nPeapleIdx].PaintInfo(Npc[m_nPeapleIdx].GetNpcPate(), true);
  2542. }
  2543. }
  2544. else
  2545. {
  2546. Npc[m_nPeapleIdx].DrawBlood();
  2547. }
  2548. return;
  2549. }
  2550. if (m_nObjectIdx)
  2551. {
  2552. if (!ObjSet.CheckShowName())
  2553. Object[m_nObjectIdx].DrawInfo();
  2554. // Object[m_nObjectIdx].DrawBorder();
  2555. return;
  2556. }
  2557. }
  2558. #endif
  2559. #ifndef _SERVER
  2560. void KPlayer::GetEchoDamage(int* nMin, int* nMax, int nType)
  2561. {
  2562. int nSkillId;
  2563. *nMin = 0;
  2564. *nMax = 0;
  2565. if (m_nIndex <= 0 || m_nIndex >= MAX_NPC 
  2566. || nType < 0 || nType > 1 
  2567. || NULL == nMin || NULL == nMax)
  2568. return;
  2569. nSkillId = (0 == nType)?m_nLeftSkillID:m_nRightSkillID;
  2570. int nLevel = Npc[m_nIndex].m_SkillList.GetCurrentLevel(nSkillId);
  2571. if (nSkillId <= 0 ||nLevel <= 0 || nLevel >= MAX_SKILLLEVEL)
  2572. return;
  2573. KMagicAttrib* pMagicData = NULL;
  2574. KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nSkillId, nLevel);
  2575. if (!pOrdinSkill) 
  2576.         return ;
  2577. switch(pOrdinSkill->GetSkillStyle())
  2578. {
  2579. case SKILL_SS_Missles: // 子弹类 本技能用于发送子弹类
  2580. case SKILL_SS_Melee:
  2581. case SKILL_SS_InitiativeNpcState: // 主动类 本技能用于改变当前Npc的主动状态
  2582. case SKILL_SS_PassivityNpcState: // 被动类 本技能用于改变Npc的被动状态
  2583. {
  2584. }
  2585. break;
  2586. default:
  2587. return;
  2588. }
  2589. BOOL bIsPhysical = pOrdinSkill->IsPhysical();
  2590. pMagicData = pOrdinSkill->GetDamageAttribs();
  2591. if (!pMagicData)
  2592. return;
  2593. int nMinNpcDamage = Npc[m_nIndex].m_PhysicsDamage.nValue[0] + Npc[m_nIndex].m_CurrentAddPhysicsDamage;
  2594. int nMaxNpcDamage = Npc[m_nIndex].m_PhysicsDamage.nValue[2] + Npc[m_nIndex].m_CurrentAddPhysicsDamage;
  2595. // Skip attackrating
  2596. pMagicData++;
  2597. // Skip ignoredefense
  2598. pMagicData++;
  2599. // Calc physics damage
  2600. if (magic_physicsenhance_p == pMagicData->nAttribType)
  2601. {
  2602. *nMin += nMinNpcDamage * (100 + pMagicData->nValue[0]) / 100;
  2603. *nMax += nMaxNpcDamage * (100 + pMagicData->nValue[0]) / 100;
  2604. int nEnhance;
  2605. if (equip_meleeweapon == m_ItemList.GetWeaponType())
  2606. {
  2607. nEnhance = Npc[m_nIndex].m_CurrentMeleeEnhance[m_ItemList.GetWeaponParticular()];
  2608. }
  2609. else if (equip_rangeweapon == m_ItemList.GetWeaponType())
  2610. {
  2611. nEnhance = Npc[m_nIndex].m_CurrentRangeEnhance;
  2612. }
  2613. else 
  2614. {
  2615. nEnhance = Npc[m_nIndex].m_CurrentHandEnhance;
  2616. }
  2617. *nMin += nMinNpcDamage * nEnhance / 100;
  2618. *nMax += nMaxNpcDamage * nEnhance / 100;
  2619. }
  2620. else if (magic_physicsdamage_v == pMagicData->nAttribType)
  2621. {
  2622. *nMin += pMagicData->nValue[0];
  2623. *nMax += pMagicData->nValue[2];
  2624. }
  2625. pMagicData++;
  2626. // Calc cold damage
  2627. if (magic_colddamage_v == pMagicData->nAttribType)
  2628. {
  2629. *nMin += pMagicData->nValue[0];
  2630. *nMax += pMagicData->nValue[2];
  2631. }
  2632. if (bIsPhysical)
  2633. {
  2634. *nMin += Npc[m_nIndex].m_CurrentColdDamage.nValue[0];
  2635. *nMax += Npc[m_nIndex].m_CurrentColdDamage.nValue[2];
  2636. }
  2637. pMagicData++;
  2638. // Calc fire damage
  2639. if (magic_firedamage_v == pMagicData->nAttribType)
  2640. {
  2641. *nMin += pMagicData->nValue[0];
  2642. *nMax += pMagicData->nValue[2];
  2643. }
  2644. if (bIsPhysical)
  2645. {
  2646. *nMin += Npc[m_nIndex].m_CurrentFireDamage.nValue[0];
  2647. *nMax += Npc[m_nIndex].m_CurrentFireDamage.nValue[2];
  2648. }
  2649. pMagicData++;
  2650. // Calc lighting damage
  2651. if (magic_lightingdamage_v == pMagicData->nAttribType)
  2652. {
  2653. *nMin += pMagicData->nValue[0];
  2654. *nMax += pMagicData->nValue[2];
  2655. }
  2656. if (bIsPhysical)
  2657. {
  2658. *nMin += Npc[m_nIndex].m_CurrentLightDamage.nValue[0];
  2659. *nMax += Npc[m_nIndex].m_CurrentLightDamage.nValue[2];
  2660. }
  2661. pMagicData++;
  2662. // Calc poison damage
  2663. if (magic_poisondamage_v == pMagicData->nAttribType)
  2664. {
  2665. if (pMagicData->nValue[2] > 0)
  2666. {
  2667. int nPoisonDamage = (pMagicData->nValue[0] * pMagicData->nValue[1] / pMagicData->nValue[2]);
  2668. *nMin += nPoisonDamage;
  2669. *nMax += nPoisonDamage;
  2670. }
  2671. }
  2672. if (bIsPhysical)
  2673. {
  2674. if (Npc[m_nIndex].m_CurrentPoisonDamage.nValue[2] > 0)
  2675. {
  2676. int nPoisonDamage = (Npc[m_nIndex].m_CurrentPoisonDamage.nValue[0]
  2677. * Npc[m_nIndex].m_CurrentPoisonDamage.nValue[1] 
  2678. / Npc[m_nIndex].m_CurrentPoisonDamage.nValue[2]);
  2679. *nMin += nPoisonDamage;
  2680. *nMax += nPoisonDamage;
  2681. }
  2682. }
  2683. pMagicData++;
  2684. // Calc magic damage
  2685. if (magic_magicdamage_v == pMagicData->nAttribType)
  2686. {
  2687. *nMin += pMagicData->nValue[0];
  2688. *nMax += pMagicData->nValue[2];
  2689. }
  2690. }
  2691. #endif
  2692. void KPlayer::SetNpcDamageAttrib()
  2693. {
  2694. SetNpcPhysicsDamage();
  2695. }
  2696. #ifdef _SERVER
  2697. void KPlayer::TobeExchangeServer(DWORD dwMapID, int nX, int nY)
  2698. {
  2699. if (!m_dwID || m_nNetConnectIdx == -1)
  2700. return;
  2701. m_sExchangePos.m_dwMapID = dwMapID;
  2702. m_sExchangePos.m_nX = nX;
  2703. m_sExchangePos.m_nY = nY;
  2704. m_bExchangeServer = TRUE;
  2705. }
  2706. #endif
  2707. /*
  2708. #ifdef _SERVER
  2709. void KPlayer::UpdateEnterGamePos(DWORD dwSubWorldID, int nX, int nY, int nFightMode)
  2710. {
  2711. TRoleData* pData = (TRoleData *)&m_SaveBuffer;
  2712. pData->BaseInfo.cFightMode = nFightMode;
  2713. pData->BaseInfo.cUseRevive = 0;
  2714. pData->BaseInfo.ientergameid = dwSubWorldID;
  2715. pData->BaseInfo.ientergamex = nX;
  2716. pData->BaseInfo.ientergamey = nY;
  2717. }
  2718. #endif
  2719. */
  2720. #ifdef _SERVER
  2721. BOOL KPlayer::IsExchangingServer()
  2722. {
  2723. return m_bExchangeServer;
  2724. }
  2725. #endif
  2726. #ifdef _SERVER
  2727. void KPlayer::SetLastNetOperationTime(int nTime)
  2728. {
  2729. if (m_nNetConnectIdx == -1 || m_dwID == 0 || m_nIndex <= 0)
  2730. return;
  2731. m_nLastNetOperationTime = nTime;
  2732. if (m_bSleepMode)
  2733. {
  2734. m_bSleepMode = FALSE;
  2735. NPC_SLEEP_SYNC SleepSync;
  2736. SleepSync.ProtocolType = s2c_npcsleepmode;
  2737. SleepSync.bSleep = m_bSleepMode;
  2738. SleepSync.NpcID = Npc[m_nIndex].m_dwID;
  2739. Npc[m_nIndex].SendDataToNearRegion(&SleepSync, sizeof(NPC_SLEEP_SYNC));
  2740. }
  2741. }
  2742. #endif
  2743. #ifdef _SERVER
  2744. BOOL KPlayer::CreateTong(int nCamp, char *lpszTongName)
  2745. {
  2746. return this->m_cTong.Create(nCamp, lpszTongName);
  2747. }
  2748. #endif
  2749. #ifdef _SERVER
  2750. void KPlayer::RepairItem(DWORD dwItemID)
  2751. {
  2752. int nIdx = m_ItemList.SearchID(dwItemID);
  2753. int nCost = Item[nIdx].GetRepairPrice();
  2754. if (!nCost)
  2755. return;
  2756. int nMaxDur = Item[nIdx].GetMaxDurability();
  2757. int nDur = Item[nIdx].GetDurability();
  2758. if (Pay(nCost) && m_nNetConnectIdx >= 0)
  2759. {
  2760. Item[nIdx].SetDurability(nMaxDur);
  2761. ITEM_DURABILITY_CHANGE IDC;
  2762. IDC.ProtocolType = s2c_itemdurabilitychange;
  2763. IDC.dwItemID = dwItemID;
  2764. IDC.nChange = nMaxDur - nDur;
  2765. if (g_pServer)
  2766. g_pServer->PackDataToClient(m_nNetConnectIdx, &IDC, sizeof(ITEM_DURABILITY_CHANGE));
  2767. }
  2768. }
  2769. #endif
  2770. #ifdef _SERVER
  2771. void KPlayer::SetExtPoint(int nPoint, int nChangePoint)
  2772. {
  2773. m_nExtPoint = nPoint;
  2774. m_nChangeExtPoint = nChangePoint;
  2775. }
  2776. int KPlayer::GetExtPoint()
  2777. {
  2778. return m_nExtPoint;
  2779. }
  2780. BOOL KPlayer::PayExtPoint(int nPoint)
  2781. {
  2782. if (m_nExtPoint < nPoint)
  2783. return FALSE;
  2784. m_nExtPoint -= nPoint;
  2785. m_nChangeExtPoint += nPoint;
  2786. return TRUE;
  2787. }
  2788. int KPlayer::GetExtPointChanged()
  2789. {
  2790. return m_nChangeExtPoint;
  2791. }
  2792. #endif
  2793. // 物品相应的操作:
  2794. //     获得物品:1、从地上拣物品 2、脚本控制直接给 3、交易 4、player 之间赠
  2795. //               送(通过交易实现)
  2796. //         客户端鼠标点在物件上,然后客户端通过物件得出物品id、应该出现在装备栏或者
  2797. //         物品栏的位置或者跟随鼠标的计算,把计算结果发给服务器;服务器收到后首先判
  2798. //         断玩家与物品的位置关系,然后检查客户端的计算结果是否正确,然后进行相应的
  2799. //         处理,把处理结果发给客户端
  2800. //     物品的位置调整:客户端处理好物品来源位置、鼠标上物品目的位置,然后发给服务器,
  2801. //     服务器确认后通知客户端最终确定的操作(如果成功,把协议原样发回去);如果有数
  2802. //     值等其他变化,另外通知客户端;
  2803. //     使用物品:1、吃药 2、装备(鼠标右键点击)
  2804. //         客户端向服务器端申请吃什么位置的药,同时客户端的相应数值先作相应变化,服
  2805. //         务器收到客户端申请后,处理完相应数据,通过player同步的方式通知客户端数据
  2806. //         的变化;
  2807. //         装备:鼠标右键点在一个装备上,自动处理装备上、卸下的位置信息,发给服务器,
  2808. //         服务器处理完后原样发回来;
  2809. // 交易的处理还没有