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

模拟服务器

开发平台:

C/C++

  1. #include "KEngine.h"
  2. #include "KCore.h"
  3. #ifndef _SERVER
  4. #include "../../Headers/IClient.h"
  5. #include "CoreShell.h"
  6. #include "KViewItem.h"
  7. #endif
  8. #include "KObjSet.h"
  9. #include "KNpcSet.h"
  10. #include "KPlayer.h"
  11. #include "KPlayerSet.h"
  12. #include "KPlayerTeam.h"
  13. #include "KPlayerFaction.h"
  14. #include "KNpc.h"
  15. #include "KSubWorld.h"
  16. #include "LuaFuns.h"
  17. #include "KProtocolProcess.h"
  18. #include "KSkills.h"
  19. #include "KItemSet.h"
  20. #include "KBuySell.h"
  21. #include "KSubWorldSet.h"
  22. //#include "MyAssert.h"
  23. #include "Scene/ObstacleDef.h"
  24. #include "KMath.h"
  25. #ifndef _SERVER
  26. #include "SceneKScenePlaceC.h"
  27. #endif
  28. #include "KTongProtocol.h"
  29. #include "KLadder.h"
  30. //#define WAIGUA_ZROC
  31. KProtocolProcess g_ProtocolProcess;
  32. KProtocolProcess::KProtocolProcess()
  33. {
  34. ZeroMemory(ProcessFunc, sizeof(ProcessFunc));
  35. #ifndef _SERVER
  36. ProcessFunc[s2c_login] = NULL;
  37. ProcessFunc[s2c_logout] = NULL;
  38. ProcessFunc[s2c_syncend] = SyncEnd;
  39. ProcessFunc[s2c_synccurplayer] = SyncCurPlayer;
  40. ProcessFunc[s2c_synccurplayerskill] = s2cSyncAllSkill;
  41. ProcessFunc[s2c_synccurplayernormal] = SyncCurNormalData;
  42. ProcessFunc[s2c_newplayer] = NULL;
  43. ProcessFunc[s2c_removeplayer] = NULL;
  44. ProcessFunc[s2c_syncworld] = SyncWorld;
  45. ProcessFunc[s2c_syncplayer] = SyncPlayer;
  46. ProcessFunc[s2c_syncplayermin] = SyncPlayerMin;
  47. ProcessFunc[s2c_syncnpc] = SyncNpc;
  48. ProcessFunc[s2c_syncnpcmin] = SyncNpcMin;
  49. ProcessFunc[s2c_syncnpcminplayer] = SyncNpcMinPlayer;
  50. ProcessFunc[s2c_objadd] = SyncObjectAdd;
  51. ProcessFunc[s2c_syncobjstate] = SyncObjectState;
  52. ProcessFunc[s2c_syncobjdir] = SyncObjectDir;
  53. ProcessFunc[s2c_objremove] = SyncObjectRemove;
  54. ProcessFunc[s2c_objTrapAct] = SyncObjectTrap;
  55. ProcessFunc[s2c_npcremove] = NetCommandRemoveNpc;
  56. ProcessFunc[s2c_npcwalk] = NetCommandWalk;
  57. ProcessFunc[s2c_npcrun] = NetCommandRun;
  58. ProcessFunc[s2c_npcattack] = NULL;
  59. ProcessFunc[s2c_npcmagic] = NULL;
  60. ProcessFunc[s2c_npcjump] = NetCommandJump;
  61. ProcessFunc[s2c_npctalk] = NULL;
  62. ProcessFunc[s2c_npchurt] = NetCommandHurt;
  63. ProcessFunc[s2c_npcdeath] = NetCommandDeath;
  64. ProcessFunc[s2c_npcchgcurcamp] = NetCommandChgCurCamp;
  65. ProcessFunc[s2c_npcchgcamp] = NetCommandChgCamp;
  66. ProcessFunc[s2c_skillcast] = NetCommandSkill;
  67. ProcessFunc[s2c_playertalk] = NULL;
  68. ProcessFunc[s2c_playerexp] = s2cPlayerExp;
  69. ProcessFunc[s2c_teaminfo] = s2cShowTeamInfo;
  70. ProcessFunc[s2c_teamselfinfo] = s2cUpdataSelfTeamInfo;
  71. ProcessFunc[s2c_teamapplyinfofalse] = s2cApplyTeamInfoFalse;
  72. ProcessFunc[s2c_teamcreatesuccess] = s2cCreateTeam;
  73. ProcessFunc[s2c_teamcreatefalse] = s2cApplyCreateTeamFalse;
  74. ProcessFunc[s2c_teamopenclose] = s2cSetTeamState;
  75. ProcessFunc[s2c_teamgetapply] = s2cApplyAddTeam;
  76. ProcessFunc[s2c_teamaddmember] = s2cTeamAddMember;
  77. ProcessFunc[s2c_teamleave] = s2cLeaveTeam;
  78. ProcessFunc[s2c_teamchangecaptain] = s2cTeamChangeCaptain;
  79. ProcessFunc[s2c_playerfactiondata] = s2cSetFactionData;
  80. ProcessFunc[s2c_playerleavefaction] = s2cLeaveFaction;
  81. ProcessFunc[s2c_playerfactionskilllevel] = s2cFactionSkillOpen;
  82. ProcessFunc[s2c_playersendchat] = s2cGetChat;
  83. ProcessFunc[s2c_playersyncleadexp] = s2cGetLeadExp;
  84. ProcessFunc[s2c_playerlevelup] = s2cLevelUp;
  85. ProcessFunc[s2c_teammatelevel] = s2cGetTeammateLevel;
  86. ProcessFunc[s2c_playersyncattribute] = s2cGetCurAttribute;
  87. ProcessFunc[s2c_playerskilllevel] = s2cGetSkillLevel;
  88. ProcessFunc[s2c_syncitem] = s2cSyncItem;
  89. ProcessFunc[s2c_removeitem] = s2cRemoveItem;
  90. ProcessFunc[s2c_syncmoney] = s2cSyncMoney;
  91. ProcessFunc[s2c_playermoveitem] = s2cMoveItem;
  92. ProcessFunc[s2c_scriptaction] = SyncScriptAction;
  93. ProcessFunc[s2c_chatapplyaddfriend] = s2cChatGetApplyAddFriend;
  94. ProcessFunc[s2c_chataddfriend] = s2cChatAddFriend;
  95. ProcessFunc[s2c_chatrefusefriend] = s2cChatBeRefusedAddFriend;
  96. ProcessFunc[s2c_chataddfriendfail] = s2cChatAddFriendFail;
  97. ProcessFunc[s2c_chatloginfriendnoname] = s2cChatLoginFriendNoName;
  98. ProcessFunc[s2c_chatloginfriendname] = s2cChatLoginFriendName;
  99. ProcessFunc[s2c_chatonefrienddata] = s2cChatAddOneFriend;
  100. ProcessFunc[s2c_chatfriendonline] = s2cChatFriendOnline;
  101. ProcessFunc[s2c_chatdeletefriend] = s2cChatDeleteFriend;
  102. ProcessFunc[s2c_chatfriendoffline] = s2cChatFriendOffLine;
  103. ProcessFunc[s2c_syncrolelist] = s2cSyncRoleList;
  104. ProcessFunc[s2c_tradechangestate] = s2cTradeChangeState;
  105. ProcessFunc[s2c_npcsetmenustate] = s2cNpcSetMenuState;
  106. ProcessFunc[s2c_trademoneysync] = s2cTradeMoneySync;
  107. ProcessFunc[s2c_tradedecision] = s2cTradeDecision;
  108. ProcessFunc[s2c_chatscreensingleerror] = s2cChatScreenSingleError;
  109. ProcessFunc[s2c_syncnpcstate] = s2cUpdateNpcState;
  110. ProcessFunc[s2c_teaminviteadd] = s2cTeamInviteAdd;
  111. ProcessFunc[s2c_tradepressoksync] = s2cTradePressOkSync;
  112. ProcessFunc[s2c_ping] = s2cPing;
  113. ProcessFunc[s2c_npcsit] = NetCommandSit;
  114. ProcessFunc[s2c_opensalebox] = OpenSaleBox;
  115. ProcessFunc[s2c_castskilldirectly] = s2cDirectlyCastSkill;
  116. ProcessFunc[s2c_msgshow] = s2cShowMsg;
  117. ProcessFunc[s2c_syncstateeffect] = SyncStateEffect;
  118. ProcessFunc[s2c_openstorebox] = OpenStoreBox;
  119. ProcessFunc[s2c_playerrevive] = PlayerRevive;
  120. ProcessFunc[s2c_requestnpcfail] = RequestNpcFail;
  121. ProcessFunc[s2c_tradeapplystart] = s2cTradeApplyStart;
  122. ProcessFunc[s2c_rolenewdelresponse] = NULL;
  123. ProcessFunc[s2c_ItemAutoMove] = s2cItemAutoMove;
  124. ProcessFunc[s2c_itemexchangefinish] = FinishedItemExchange;
  125. ProcessFunc[s2c_changeweather] = s2cChangeWeather;
  126. ProcessFunc[s2c_pksyncnormalflag] = s2cPKSyncNormalFlag;
  127. ProcessFunc[s2c_pksyncenmitystate] = s2cPKSyncEnmityState;
  128. ProcessFunc[s2c_pksyncexercisestate] = s2cPKSyncExerciseState;
  129. ProcessFunc[s2c_pksyncpkvalue] = s2cPKValueSync;
  130. ProcessFunc[s2c_npcsleepmode] = NpcSleepSync;
  131. ProcessFunc[s2c_viewequip] = s2cViewEquip;
  132. ProcessFunc[s2c_ladderresult] = LadderResult;
  133. ProcessFunc[s2c_ladderlist] = LadderList;
  134. ProcessFunc[s2c_tongcreate] = s2cTongCreate;
  135. ProcessFunc[s2c_replyclientping] = ServerReplyClientPing;
  136. ProcessFunc[s2c_npcgoldchange] = s2cNpcGoldChange;
  137. ProcessFunc[s2c_itemdurabilitychange] = ItemChangeDurability;
  138. ProcessFunc[s2c_extend] = s2cExtend;
  139. ProcessFunc[s2c_extendchat] = s2cExtendChat;
  140. ProcessFunc[s2c_extendfriend] = s2cExtendFriend;
  141. ProcessFunc[s2c_extendtong] = s2cExtendTong;
  142. #else
  143. ProcessFunc[c2s_login] = NULL;
  144. ProcessFunc[c2s_logiclogin] = NULL;
  145. ProcessFunc[c2s_syncend] = NULL;
  146. ProcessFunc[c2s_loadplayer] = NULL;
  147. ProcessFunc[c2s_newplayer] = NULL;
  148. ProcessFunc[c2s_removeplayer] = &KProtocolProcess::RemoveRole;
  149. ProcessFunc[c2s_requestworld] = NULL;
  150. ProcessFunc[c2s_requestplayer] = NULL;
  151. ProcessFunc[c2s_requestnpc] = &KProtocolProcess::NpcRequestCommand;
  152. ProcessFunc[c2s_requestobj] = &KProtocolProcess::ObjRequestCommand;
  153. ProcessFunc[c2s_npcwalk] = &KProtocolProcess::NpcWalkCommand;
  154. ProcessFunc[c2s_npcrun] = &KProtocolProcess::NpcRunCommand;
  155. ProcessFunc[c2s_npcskill] = &KProtocolProcess::NpcSkillCommand;
  156. ProcessFunc[c2s_npcjump] = &KProtocolProcess::NpcJumpCommand;
  157. ProcessFunc[c2s_npctalk] = &KProtocolProcess::NpcTalkCommand;
  158. ProcessFunc[c2s_npchurt] = NULL;
  159. ProcessFunc[c2s_npcdeath] = NULL;
  160. ProcessFunc[c2s_playertalk] = &KProtocolProcess::PlayerTalkCommand;
  161. ProcessFunc[c2s_teamapplyinfo] = &KProtocolProcess::PlayerApplyTeamInfo;
  162. ProcessFunc[c2s_teamapplycreate] = &KProtocolProcess::PlayerApplyCreateTeam;
  163. ProcessFunc[c2s_teamapplyopenclose] = &KProtocolProcess::PlayerApplyTeamOpenClose;
  164. ProcessFunc[c2s_teamapplyadd] = &KProtocolProcess::PlayerApplyAddTeam;
  165. ProcessFunc[c2s_teamacceptmember] = &KProtocolProcess::PlayerAcceptTeamMember;
  166. ProcessFunc[c2s_teamapplyleave] = &KProtocolProcess::PlayerApplyLeaveTeam;
  167. ProcessFunc[c2s_teamapplykickmember] = &KProtocolProcess::PlayerApplyTeamKickMember;
  168. ProcessFunc[c2s_teamapplychangecaptain] = &KProtocolProcess::PlayerApplyTeamChangeCaptain;
  169. ProcessFunc[c2s_teamapplydismiss] = &KProtocolProcess::PlayerApplyTeamDismiss;
  170. ProcessFunc[c2s_playerapplysetpk] = &KProtocolProcess::PlayerApplySetPK;
  171. ProcessFunc[c2s_playerapplyfactiondata] = &KProtocolProcess::PlayerApplyFactionData;
  172. ProcessFunc[c2s_playersendchat] = &KProtocolProcess::PlayerSendChat;
  173. ProcessFunc[c2s_playeraddbaseattribute] = &KProtocolProcess::PlayerAddBaseAttribute;
  174. ProcessFunc[c2s_playerapplyaddskillpoint] = &KProtocolProcess::PlayerApplyAddSkillPoint;
  175. ProcessFunc[c2s_playereatitem] = &KProtocolProcess::PlayerEatItem;
  176. ProcessFunc[c2s_playerpickupitem] = &KProtocolProcess::PlayerPickUpItem;
  177. ProcessFunc[c2s_playermoveitem] = &KProtocolProcess::PlayerMoveItem;
  178. ProcessFunc[c2s_playersellitem] = &KProtocolProcess::PlayerSellItem;
  179. ProcessFunc[c2s_playerbuyitem] = &KProtocolProcess::PlayerBuyItem;
  180. ProcessFunc[c2s_playerthrowawayitem] = &KProtocolProcess::PlayerDropItem;
  181. ProcessFunc[c2s_playerselui] = &KProtocolProcess::PlayerSelUI;
  182. ProcessFunc[c2s_chatsetchannel] = &KProtocolProcess::ChatSetChannel;
  183. ProcessFunc[c2s_chatapplyaddfriend] = &KProtocolProcess::ChatApplyAddFriend;
  184. ProcessFunc[c2s_chataddfriend] = &KProtocolProcess::ChatAddFriend;
  185. ProcessFunc[c2s_chatrefusefriend] = &KProtocolProcess::ChatRefuseFriend;
  186. ProcessFunc[c2s_dbplayerselect] = NULL;
  187. ProcessFunc[c2s_chatapplyresendallfriendname] = &KProtocolProcess::ChatApplyReSendAllFriendName;
  188. ProcessFunc[c2s_chatapplysendonefriendname] = &KProtocolProcess::ChatApplySendOneFriendName;
  189. ProcessFunc[c2s_chatdeletefriend] = &KProtocolProcess::ChatDeleteFriend;
  190. ProcessFunc[c2s_chatredeletefriend] = &KProtocolProcess::ChatReDeleteFriend;
  191. ProcessFunc[c2s_tradeapplystateopen] = &KProtocolProcess::TradeApplyOpen;
  192. ProcessFunc[c2s_tradeapplystateclose] = &KProtocolProcess::TradeApplyClose;
  193. ProcessFunc[c2s_tradeapplystart] = &KProtocolProcess::TradeApplyStart;
  194. ProcessFunc[c2s_trademovemoney] = &KProtocolProcess::TradeMoveMoney;
  195. ProcessFunc[c2s_tradedecision] = &KProtocolProcess::TradeDecision;
  196. ProcessFunc[c2s_dialognpc] = &KProtocolProcess::DialogNpc;
  197. ProcessFunc[c2s_teaminviteadd] = &KProtocolProcess::TeamInviteAdd;
  198. ProcessFunc[c2s_changeauraskill] = &KProtocolProcess::ChangeAuraSkill;
  199. ProcessFunc[c2s_teamreplyinvite] = &KProtocolProcess::TeamReplyInvite;
  200. ProcessFunc[c2s_ping] = NULL;//ReplyPing;
  201. ProcessFunc[c2s_npcsit] = &KProtocolProcess::NpcSitCommand;
  202. ProcessFunc[c2s_objmouseclick] = &KProtocolProcess::ObjMouseClick;
  203. ProcessFunc[c2s_storemoney] = &KProtocolProcess::StoreMoneyCommand;
  204. ProcessFunc[c2s_playerrevive] = &KProtocolProcess::NpcReviveCommand;
  205. ProcessFunc[c2s_tradereplystart] = &KProtocolProcess::c2sTradeReplyStart;
  206. ProcessFunc[c2s_pkapplychangenormalflag] = &KProtocolProcess::c2sPKApplyChangeNormalFlag;
  207. ProcessFunc[c2s_pkapplyenmity] = &KProtocolProcess::c2sPKApplyEnmity;
  208. ProcessFunc[c2s_viewequip] = &KProtocolProcess::c2sViewEquip;
  209. ProcessFunc[c2s_ladderquery] = &KProtocolProcess::LadderQuery;
  210. ProcessFunc[c2s_repairitem] = &KProtocolProcess::ItemRepair;
  211. #endif
  212. }
  213. KProtocolProcess::~KProtocolProcess()
  214. {
  215. }
  216. #ifndef _SERVER
  217. void KProtocolProcess::ProcessNetMsg(BYTE* pMsg)
  218. {
  219. if (!pMsg || pMsg[0] <= s2c_clientbegin || pMsg[0] >= s2c_end || ProcessFunc[pMsg[0]] == NULL)
  220. {
  221. g_DebugLog("[error]Net Msg Error");
  222. return;
  223. }
  224. g_DebugLog("[net]Msg:%c", pMsg[0]);
  225. if (ProcessFunc[pMsg[0]])
  226. (this->*ProcessFunc[pMsg[0]])(pMsg);
  227. }
  228. #else
  229. void KProtocolProcess::ProcessNetMsg(int nIndex, BYTE* pMsg)
  230. {
  231. _ASSERT(pMsg && pMsg[0] > c2s_gameserverbegin && pMsg[0] < c2s_end);
  232. BYTE byProtocol = pMsg[0];
  233. _ASSERT(nIndex > 0 && nIndex < MAX_PLAYER);
  234. if (ProcessFunc[byProtocol])
  235. {
  236. (this->*ProcessFunc[byProtocol])(nIndex, pMsg);
  237. Player[nIndex].SetLastNetOperationTime(g_SubWorldSet.GetGameTime());
  238. }
  239. }
  240. #endif
  241. #ifndef _SERVER
  242. void KProtocolProcess::NpcSleepSync(BYTE* pMsg)
  243. {
  244. NPC_SLEEP_SYNC* pSync = (NPC_SLEEP_SYNC *)pMsg;
  245. DWORD dwNpcId = pSync->NpcID;
  246. int nIdx = NpcSet.SearchID(dwNpcId);
  247. if (nIdx > 0)
  248. {
  249. Npc[nIdx].SetSleepMode((BOOL)pSync->bSleep);
  250. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  251. }
  252. }
  253. void KProtocolProcess::s2cPing(BYTE* pMsg)
  254. {
  255. // DWORD dwTimer = GetTickCount();
  256. // PING_COMMAND* PingCmd = (PING_COMMAND *)pMsg;
  257. //
  258. // dwTimer -= PingCmd->m_dwTime;
  259. // dwTimer >>= 1;
  260. // g_SubWorldSet.SetPing(dwTimer);
  261. // g_bPingReply = TRUE;
  262. DWORD dwTimer = GetTickCount();
  263. PING_COMMAND* PingCmd = (PING_COMMAND *)pMsg;
  264. PING_CLIENTREPLY_COMMAND pcc;
  265. pcc.ProtocolType = c2s_ping;
  266. pcc.m_dwReplyServerTime = PingCmd->m_dwTime;
  267. pcc.m_dwClientTime = dwTimer;
  268. g_pClient->SendPackToServer(&pcc, sizeof(PING_CLIENTREPLY_COMMAND));
  269. //g_SubWorldSet.SetPing(PingCmd->m_dwTime);
  270. }
  271. void KProtocolProcess::ServerReplyClientPing(BYTE* pMsg)
  272. {
  273. DWORD dwTimer = GetTickCount();
  274. PING_COMMAND* pPc = (PING_COMMAND *)pMsg;
  275. dwTimer -= pPc->m_dwTime;
  276. dwTimer >>= 1;
  277. g_SubWorldSet.SetPing(dwTimer);
  278. }
  279. void KProtocolProcess::s2cPlayerExp(BYTE* pMsg)
  280. {
  281. PLAYER_EXP_SYNC *pExp = (PLAYER_EXP_SYNC*)pMsg;
  282. Player[CLIENT_PLAYER_INDEX].s2cSetExp(pExp->m_nExp);
  283. }
  284. void KProtocolProcess::s2cChatScreenSingleError(BYTE* pMsg)
  285. {
  286. CHAT_SCREENSINGLE_ERROR_SYNC *pError = (CHAT_SCREENSINGLE_ERROR_SYNC*)pMsg;
  287. // 通知界面屏幕单聊不成功
  288. char szName[32];
  289. memset(szName, 0, sizeof(szName));
  290. memcpy(szName, pError->m_szName, pError->m_wLength + 1 + sizeof(pError->m_szName) - sizeof(CHAT_SCREENSINGLE_ERROR_SYNC));
  291. KSystemMessage sMsg;
  292. sprintf(sMsg.szMessage, MSG_CHAT_TAR_REFUSE_SINGLE_TALK, szName);
  293. sMsg.eType = SMT_NORMAL;
  294. sMsg.byConfirmType = SMCT_NONE;
  295. sMsg.byPriority = 0;
  296. sMsg.byParamSize = 0;
  297. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  298. }
  299. void KProtocolProcess::NetCommandChgCamp(BYTE* pMsg)
  300. {
  301. DWORD dwNpcId;
  302. dwNpcId = *(DWORD *)&pMsg[1];
  303. int nIdx = NpcSet.SearchID(dwNpcId);
  304. if (nIdx > 0)
  305. {
  306. Npc[nIdx].m_Camp = (int)pMsg[5];
  307. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  308. }
  309. }
  310. void KProtocolProcess::NetCommandChgCurCamp(BYTE* pMsg)
  311. {
  312. DWORD dwNpcId;
  313. dwNpcId = *(DWORD *)&pMsg[1];
  314. int nIdx = NpcSet.SearchID(dwNpcId);
  315. if (nIdx > 0)
  316. {
  317. Npc[nIdx].m_CurrentCamp = (int)pMsg[5];
  318. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  319. }
  320. }
  321. void KProtocolProcess::NetCommandDeath(BYTE* pMsg)
  322. {
  323. DWORD dwNpcID;
  324. dwNpcID = *(DWORD *)&pMsg[1];
  325. int nIdx = NpcSet.SearchID(dwNpcID);
  326. if (nIdx > 0)
  327. {
  328. //Npc[nIdx].SendCommand(do_death);
  329. Npc[nIdx].ProcNetCommand(do_death);
  330. Npc[nIdx].m_CurrentLife = 0;
  331. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  332. g_DebugLog("[Death]Net command comes");
  333. }
  334. }
  335. void KProtocolProcess::NetCommandJump(BYTE* pMsg)
  336. {
  337. NPC_JUMP_SYNC* pNetCommandJump = (NPC_JUMP_SYNC *)pMsg;
  338. DWORD dwNpcId = pNetCommandJump->ID;
  339. int nIdx = NpcSet.SearchID(dwNpcId);
  340. if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  341. {
  342. Npc[nIdx].SendCommand(do_jump, pNetCommandJump->nMpsX, pNetCommandJump->nMpsY);
  343. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  344. }
  345. }
  346. void KProtocolProcess::NetCommandHurt(BYTE* pMsg)
  347. {
  348. NPC_HURT_SYNC* pSync = (NPC_HURT_SYNC *)pMsg;
  349. int nIdx = NpcSet.SearchID(pSync->ID);
  350. if (nIdx > 0)
  351. {
  352. //Npc[nIdx].SendCommand(do_hurt, pSync->nFrames, pSync->nX, pSync->nY);
  353. Npc[nIdx].ProcNetCommand(do_hurt, pSync->nFrames, pSync->nX, pSync->nY);
  354. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  355. }
  356. }
  357. void KProtocolProcess::NetCommandRemoveNpc(BYTE* pMsg)
  358. {
  359. DWORD dwNpcID;
  360. dwNpcID = *(DWORD *)&pMsg[1];
  361. int nIdx = NpcSet.SearchID(dwNpcID);
  362. if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  363. {
  364. if (Npc[nIdx].m_RegionIndex >= 0)
  365. {
  366. // zroc change
  367. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].RemoveNpc(nIdx);
  368. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].DecRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  369. // SubWorld[Npc[nIdx].m_SubWorldIndex].m_Region[Npc[nIdx].m_RegionIndex].RemoveNpc(nIdx);
  370. }
  371. NpcSet.Remove(nIdx);
  372. }
  373. }
  374. void KProtocolProcess::NetCommandRun(BYTE* pMsg)
  375. {
  376. DWORD dwNpcID;
  377. DWORD MapX, MapY;
  378. dwNpcID = *(DWORD *)&pMsg[1];
  379. MapX = *(int *)&pMsg[5];
  380. MapY = *(int *)&pMsg[9];
  381. int nIdx = NpcSet.SearchID(dwNpcID);
  382. if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  383. {
  384. Npc[nIdx].SendCommand(do_run, MapX, MapY);
  385. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  386. }
  387. }
  388. void KProtocolProcess::NetCommandSit(BYTE* pMsg)
  389. {
  390. NPC_SIT_SYNC* pSitSync;
  391. pSitSync = (NPC_SIT_SYNC *)pMsg;
  392. int nIdx = NpcSet.SearchID(pSitSync->ID);
  393. if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  394. {
  395. Npc[nIdx].SendCommand(do_sit);
  396. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  397. }
  398. }
  399. void KProtocolProcess::OpenSaleBox(BYTE* pMsg)
  400. {
  401. SALE_BOX_SYNC* pSale = (SALE_BOX_SYNC *)pMsg;
  402. BuySell.OpenSale(pSale->nShopIndex);
  403. }
  404. void KProtocolProcess::OpenStoreBox(BYTE* pMsg)
  405. {
  406. CoreDataChanged(GDCNI_OPEN_STORE_BOX, NULL, NULL);
  407. }
  408. void KProtocolProcess::PlayerRevive(BYTE* pMsg)
  409. {
  410. NPC_REVIVE_SYNC* pSync = (NPC_REVIVE_SYNC*)pMsg;
  411. int nIdx = NpcSet.SearchID(pSync->ID);
  412. if (nIdx > 0)
  413. {
  414. if (!Npc[nIdx].IsPlayer() && pSync->Type == REMOTE_REVIVE_TYPE)
  415. {
  416. SubWorld[0].m_WorldMessage.Send(GWM_NPC_DEL, nIdx);
  417. return;
  418. }
  419. else
  420. {
  421. Npc[nIdx].ProcNetCommand(do_revive);
  422. }
  423. }
  424. }
  425. void KProtocolProcess::RequestNpcFail(BYTE* pMsg)
  426. {
  427. NPC_REQUEST_FAIL* pNpcSync = (NPC_REQUEST_FAIL *)pMsg;
  428. if (NpcSet.IsNpcRequestExist(pNpcSync->ID))
  429. NpcSet.RemoveNpcRequest(pNpcSync->ID);
  430. }
  431. void KProtocolProcess::NetCommandSkill(BYTE* pMsg)
  432. {
  433. DWORD dwNpcID;
  434. int nSkillID, nSkillLevel;
  435. int MapX, MapY;
  436. dwNpcID = *(DWORD *)&pMsg[1];
  437. nSkillID = *(int *)&pMsg[5];
  438. nSkillLevel = *(int *)&pMsg[9];
  439. MapX = *(int *)&pMsg[13];
  440. MapY = *(int *)&pMsg[17];
  441. if (MapY < 0)
  442. return ;
  443. //当指定某个目标时(MapX == -1),MapY为目标的NpcdwID,需要转换成本地的NpcIndex才行
  444. if (MapX < 0)
  445. {
  446. if (MapX != -1)
  447. return;
  448. MapY = NpcSet.SearchID(MapY);
  449. if (MapY == 0)
  450. return;
  451. if (Npc[MapY].m_RegionIndex < 0)
  452. return;
  453. }
  454. int nIdx = NpcSet.SearchID(dwNpcID);
  455. if (nIdx <= 0) 
  456. return;
  457. if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  458. {
  459. Npc[nIdx].m_SkillList.SetSkillLevel(nSkillID, nSkillLevel);
  460. Npc[nIdx].SendCommand(do_skill, nSkillID, MapX, MapY);
  461. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  462. }
  463. }
  464. void KProtocolProcess::NetCommandWalk(BYTE* pMsg)
  465. {
  466. DWORD dwNpcID;
  467. DWORD MapX, MapY;
  468. dwNpcID = *(DWORD *)&pMsg[1];
  469. MapX = *(int *)&pMsg[5];
  470. MapY = *(int *)&pMsg[9];
  471. int nIdx = NpcSet.SearchID(dwNpcID);
  472. if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  473. {
  474. Npc[nIdx].SendCommand(do_walk, MapX, MapY);
  475. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  476. }
  477. }
  478. //-------------------------------------------------------------------------
  479. // 功能:收到服务器通知队伍创建失败
  480. //-------------------------------------------------------------------------
  481. void KProtocolProcess::s2cApplyCreateTeamFalse(BYTE* pMsg)
  482. {
  483. PLAYER_SEND_CREATE_TEAM_FALSE *pCreateFalse = (PLAYER_SEND_CREATE_TEAM_FALSE*)pMsg;
  484. KSystemMessage sMsg;
  485. switch (pCreateFalse->m_btErrorID)
  486. {
  487. // 已经在队伍中,说明客户端队伍数据有错误,申请重新获得队伍数据
  488. case Team_Create_Error_InTeam:
  489. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  490. break;
  491. // 当前处于不能组队状态
  492. case Team_Create_Error_CannotCreate:
  493. sprintf(sMsg.szMessage, MSG_TEAM_CANNOT_CREATE);
  494. sMsg.eType = SMT_NORMAL;
  495. sMsg.byConfirmType = SMCT_NONE;
  496. sMsg.byPriority = 0;
  497. sMsg.byParamSize = 0;
  498. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  499. break;
  500. default:
  501. sprintf(sMsg.szMessage, MSG_TEAM_CREATE_FAIL);
  502. sMsg.eType = SMT_NORMAL;
  503. sMsg.byConfirmType = SMCT_NONE;
  504. sMsg.byPriority = 0;
  505. sMsg.byParamSize = 0;
  506. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  507. break;
  508. }
  509. }
  510. //-------------------------------------------------------------------------
  511. // 功能:收到服务器通知查询某个队伍组队情况失败
  512. //-------------------------------------------------------------------------
  513. void KProtocolProcess::s2cApplyTeamInfoFalse(BYTE* pMsg)
  514. {
  515. // 界面显示队伍查询失败(not end)
  516. }
  517. //-------------------------------------------------------------------------
  518. // 功能:添加一个好友
  519. //-------------------------------------------------------------------------
  520. void KProtocolProcess::s2cChatAddFriend(BYTE* pMsg)
  521. {
  522. CHAT_ADD_FRIEND_SYNC *pFriend = (CHAT_ADD_FRIEND_SYNC*)pMsg;
  523. Player[CLIENT_PLAYER_INDEX].m_cChat.AddOne(pFriend->m_dwID, pFriend->m_nIdx, pFriend->m_szName, 0);
  524. Player[CLIENT_PLAYER_INDEX].m_cChat.SaveTeamInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  525. KSystemMessage sMsg;
  526. KUiPlayerItem sPlayer;
  527. memset(&sPlayer, 0, sizeof(KUiPlayerItem));
  528. strcpy(sPlayer.Name, pFriend->m_szName);
  529. sPlayer.uId = pFriend->m_dwID;
  530. sPlayer.nIndex = pFriend->m_nIdx;
  531. sprintf(sMsg.szMessage, MSG_CHAT_ADD_FRIEND_SUCCESS, pFriend->m_szName);
  532. sMsg.eType = SMT_FRIEND;
  533. sMsg.byConfirmType = SMCT_UI_INTERVIEW;
  534. sMsg.byPriority = 2;
  535. sMsg.byParamSize = sizeof(KUiPlayerItem);
  536. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&sPlayer);
  537. }
  538. //-------------------------------------------------------------------------
  539. // 功能:添加好友失败
  540. //-------------------------------------------------------------------------
  541. void KProtocolProcess::s2cChatAddFriendFail(BYTE* pMsg)
  542. {
  543. CHAT_ADD_FRIEND_FAIL_SYNC *pFail = (CHAT_ADD_FRIEND_FAIL_SYNC*)pMsg;
  544. char szName[32];
  545. CChatApplyListNode *pList;
  546. pList = (CChatApplyListNode*)Player[CLIENT_PLAYER_INDEX].m_cChat.m_cApplyAddList.GetHead();
  547. while (pList)
  548. {
  549. if (pList->m_nPlayerIdx == pFail->m_nTargetPlayerIdx)
  550. {
  551. g_StrCpy(szName, pList->m_szName);
  552. // 通知界面添加某人为好友操作失败
  553. KSystemMessage sMsg;
  554. sprintf(sMsg.szMessage, MSG_CHAT_ADD_FRIEND_FAIL, szName);
  555. sMsg.eType = SMT_NORMAL;
  556. sMsg.byConfirmType = SMCT_NONE;
  557. sMsg.byPriority = 0;
  558. sMsg.byParamSize = 0;
  559. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  560. return;
  561. }
  562. pList = (CChatApplyListNode*)pList->GetNext();
  563. }
  564. }
  565. //-------------------------------------------------------------------------
  566. // 功能:收到服务器过来的玩家某个聊天好友的数据(带名字)
  567. //-------------------------------------------------------------------------
  568. void KProtocolProcess::s2cChatAddOneFriend(BYTE* pMsg)
  569. {
  570. CHAT_ONE_FRIEND_DATA_SYNC *pData = (CHAT_ONE_FRIEND_DATA_SYNC*)pMsg;
  571. int nTeamNo;
  572. nTeamNo = Player[CLIENT_PLAYER_INDEX].m_cChat.CheckTeamNo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, pData->m_szName);
  573. if (nTeamNo < 0)
  574. nTeamNo = 0;
  575. Player[CLIENT_PLAYER_INDEX].m_cChat.AddOne(pData->m_dwID, pData->m_nPlayerIdx, pData->m_szName, nTeamNo);
  576. Player[CLIENT_PLAYER_INDEX].m_cChat.SaveTeamInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  577. // 通知界面得到新成员 not end
  578. }
  579. //-------------------------------------------------------------------------
  580. // 功能:被别的玩家拒绝交友
  581. //-------------------------------------------------------------------------
  582. void KProtocolProcess::s2cChatBeRefusedAddFriend(BYTE* pMsg)
  583. {
  584. CHAT_REFUSE_FRIEND_SYNC *pRefuse = (CHAT_REFUSE_FRIEND_SYNC*)pMsg;
  585. char szName[64];
  586. memset(szName, 0, sizeof(szName));
  587. memcpy(szName, pRefuse->m_szName, pRefuse->m_wLength + 1 + sizeof(pRefuse->m_szName) - sizeof(CHAT_REFUSE_FRIEND_SYNC));
  588. // 通知界面pRefuse->m_szName拒绝了他的交友申请
  589. KSystemMessage sMsg;
  590. sprintf(sMsg.szMessage, MSG_CHAT_REFUSE_FRIEND, szName);
  591. sMsg.eType = SMT_FRIEND;
  592. sMsg.byConfirmType = SMCT_CLICK;
  593. sMsg.byPriority = 1;
  594. sMsg.byParamSize = 0;
  595. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  596. }
  597. //-------------------------------------------------------------------------
  598. // 功能:得到通知好友上线
  599. //-------------------------------------------------------------------------
  600. void KProtocolProcess::s2cChatFriendOnline(BYTE* pMsg)
  601. {
  602. CHAT_FRIEND_ONLINE_SYNC *pFriend = (CHAT_FRIEND_ONLINE_SYNC*)pMsg;
  603. Player[CLIENT_PLAYER_INDEX].ChatFriendOnLine(pFriend->m_dwID, pFriend->m_nPlayerIdx);
  604. }
  605. //-------------------------------------------------------------------------
  606. // 收到服务器转发的别人添加聊天好友的申请
  607. //-------------------------------------------------------------------------
  608. void KProtocolProcess::s2cChatGetApplyAddFriend(BYTE* pMsg)
  609. {
  610. CHAT_APPLY_ADD_FRIEND_SYNC *pApply = (CHAT_APPLY_ADD_FRIEND_SYNC*)pMsg;
  611. if ( Player[CLIENT_PLAYER_INDEX].m_cChat.CheckIsFriend(pApply->m_nSrcPlayerIdx) )
  612. return;
  613. CChatApplyListNode *pNode = NULL;
  614. pNode = new CChatApplyListNode;
  615. if (pNode == NULL)
  616. return;
  617. pNode->m_nPlayerIdx = pApply->m_nSrcPlayerIdx;
  618. strcpy(pNode->m_szName, pApply->m_szSourceName);
  619. strcpy(pNode->m_szInfo, pApply->m_szInfo);
  620. Player[CLIENT_PLAYER_INDEX].m_cChat.m_cApplyAddList.AddTail(pNode);
  621. // 通知界面有人申请添加聊天好友
  622. KSystemMessage sMsg;
  623. KUiPlayerItem sPlayer;
  624. strcpy(sPlayer.Name, pApply->m_szSourceName);
  625. sPlayer.nIndex = pApply->m_nSrcPlayerIdx;
  626. sPlayer.uId = 0;
  627. sPlayer.nData = 0;
  628. sprintf(sMsg.szMessage, MSG_CHAT_GET_FRIEND_APPLY, pNode->m_szName);
  629. sMsg.eType = SMT_FRIEND;
  630. sMsg.byConfirmType = SMCT_UI_FRIEND_INVITE;
  631. sMsg.byPriority = 3;
  632. sMsg.byParamSize = sizeof(KUiPlayerItem);
  633. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&sPlayer);
  634. }
  635. //-------------------------------------------------------------------------
  636. // 功能:收到服务器过来的玩家登录时获得聊天好友数据(带名字)
  637. //-------------------------------------------------------------------------
  638. void KProtocolProcess::s2cChatLoginFriendName(BYTE* pMsg)
  639. {
  640. CHAT_LOGIN_FRIEND_NAME_SYNC *pFriend = (CHAT_LOGIN_FRIEND_NAME_SYNC*)pMsg;
  641. int nTeamNo;
  642. char szName[64];
  643. memset(szName, 0, sizeof(szName));
  644. memcpy(szName, pFriend->m_szName, pFriend->m_wLength + 1 + sizeof(pFriend->m_szName) - sizeof(CHAT_LOGIN_FRIEND_NAME_SYNC));
  645. nTeamNo = Player[CLIENT_PLAYER_INDEX].m_cChat.CheckTeamNo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, szName);
  646. if (nTeamNo < 0)
  647. nTeamNo = 0;
  648. Player[CLIENT_PLAYER_INDEX].m_cChat.AddOne(pFriend->m_dwID, pFriend->m_nPlayerIdx, szName, nTeamNo);
  649. }
  650. //-------------------------------------------------------------------------
  651. // 功能:收到服务器过来的玩家登录时获得聊天好友数据(不带名字)
  652. //-------------------------------------------------------------------------
  653. void KProtocolProcess::s2cChatLoginFriendNoName(BYTE* pMsg)
  654. {
  655. CHAT_LOGIN_FRIEND_NONAME_SYNC *pFriend = (CHAT_LOGIN_FRIEND_NONAME_SYNC*)pMsg;
  656. char szName[32];
  657. int nTeamNo;
  658. szName[0] = 0;
  659. nTeamNo = Player[CLIENT_PLAYER_INDEX].m_cChat.CheckTeamNo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, NULL);
  660. if (nTeamNo < 0)
  661. {
  662. if (Player[CLIENT_PLAYER_INDEX].m_cChat.m_nLoginGetFirstOneFriendFlag == 0) // 申请重新发送所有好友数据,带名字
  663. {
  664. Player[CLIENT_PLAYER_INDEX].m_cChat.m_nLoginGetFirstOneFriendFlag = 1;
  665. CHAT_APPLY_RESEND_ALL_FRIEND_NAME_COMMAND sApply;
  666. sApply.ProtocolType = c2s_chatapplyresendallfriendname;
  667. if (g_pClient)
  668. g_pClient->SendPackToServer((BYTE*)&sApply, sizeof(CHAT_APPLY_RESEND_ALL_FRIEND_NAME_COMMAND));
  669. }
  670. else // 申请重新发送这个好友数据,带名字
  671. {
  672. CHAT_APPLY_SEND_ONE_FRIEND_NAME_COMMAND sApply;
  673. sApply.ProtocolType = c2s_chatapplysendonefriendname;
  674. sApply.m_dwID = pFriend->m_dwID;
  675. if (g_pClient)
  676. g_pClient->SendPackToServer((BYTE*)&sApply, sizeof(CHAT_APPLY_SEND_ONE_FRIEND_NAME_COMMAND));
  677. }
  678. return;
  679. }
  680. Player[CLIENT_PLAYER_INDEX].m_cChat.AddOne(pFriend->m_dwID, pFriend->m_nPlayerIdx, szName, nTeamNo);
  681. Player[CLIENT_PLAYER_INDEX].m_cChat.SaveTeamInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  682. Player[CLIENT_PLAYER_INDEX].m_cChat.m_nLoginGetFirstOneFriendFlag = 1;
  683. }
  684. //-------------------------------------------------------------------------
  685. // 功能:收到服务器通知创建一支队伍
  686. //-------------------------------------------------------------------------
  687. void KProtocolProcess::s2cCreateTeam(BYTE* pMsg)
  688. {
  689. PLAYER_SEND_CREATE_TEAM_SUCCESS *pCreateSuccess = (PLAYER_SEND_CREATE_TEAM_SUCCESS*)pMsg;
  690. g_Team[0].CreateTeam(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Level, pCreateSuccess->nTeamServerID);
  691. Player[CLIENT_PLAYER_INDEX].m_cTeam.Release();
  692. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag = 1;
  693. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_CAPTAIN;
  694. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nApplyCaptainID = 0;
  695. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].RestoreCurrentCamp();
  696. KSystemMessage sMsg;
  697. sprintf(sMsg.szMessage, MSG_TEAM_CREATE);
  698. sMsg.eType = SMT_NORMAL;
  699. sMsg.byConfirmType = SMCT_NONE;
  700. sMsg.byPriority = 0;
  701. sMsg.byParamSize = 0;
  702. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  703. sprintf(sMsg.szMessage, MSG_TEAM_CREATE);
  704. sMsg.eType = SMT_TEAM;
  705. sMsg.byConfirmType = SMCT_CLICK;
  706. sMsg.byPriority = 1;
  707. sMsg.byParamSize = 0;
  708. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  709. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SetInstantSpr(enumINSTANT_STATE_CREATE_TEAM);
  710. }
  711. //-------------------------------------------------------------------------
  712. // 功能:收到服务器通知开放当前门派技能某等级
  713. //-------------------------------------------------------------------------
  714. void KProtocolProcess::s2cFactionSkillOpen(BYTE* pMsg)
  715. {
  716. PLAYER_FACTION_SKILL_LEVEL *pSkill = (PLAYER_FACTION_SKILL_LEVEL*)pMsg;
  717. if (Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nCurFaction < 0 || Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nCurFaction != pSkill->m_btCurFactionID)
  718. {
  719. // 申请更新门派信息
  720. Player[CLIENT_PLAYER_INDEX].ApplyFactionData();
  721. return;
  722. }
  723. // for (int i = 0; i < FACTIONS_PRR_SERIES; i++)
  724. // {
  725. // if (Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[i].m_nID == Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nCurFaction)
  726. // {
  727. // Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[i].m_nOpenLevel = pSkill->m_btLevel;
  728. // Player[CLIENT_PLAYER_INDEX].m_cFaction.OpenCurSkillLevel(Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[i].m_nOpenLevel, &Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList);
  729. // break;
  730. // }
  731. // }
  732. }
  733. //-------------------------------------------------------------------------
  734. // 功能:收到服务器发来的聊天信息
  735. //-------------------------------------------------------------------------
  736. void KProtocolProcess::s2cGetChat(BYTE* pMsg)
  737. {
  738. PLAYER_SEND_CHAT_SYNC *pChat = (PLAYER_SEND_CHAT_SYNC*)pMsg;
  739. Player[CLIENT_PLAYER_INDEX].m_cChat.GetChat(pChat);
  740. }
  741. //-------------------------------------------------------------------------
  742. // 功能:收到服务器发过来的当前某属性的点数
  743. //-------------------------------------------------------------------------
  744. void KProtocolProcess::s2cGetCurAttribute(BYTE* pMsg)
  745. {
  746. Player[CLIENT_PLAYER_INDEX].s2cGetCurAttribute(pMsg);
  747. }
  748. //-------------------------------------------------------------------------
  749. // 功能:收到服务器发来的统率力经验值
  750. //-------------------------------------------------------------------------
  751. void KProtocolProcess::s2cGetLeadExp(BYTE* pMsg)
  752. {
  753. DWORD dwLevel = Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel;
  754. PLAYER_LEAD_EXP_SYNC *pLeadExp = (PLAYER_LEAD_EXP_SYNC*)pMsg;
  755. Player[CLIENT_PLAYER_INDEX].m_dwLeadExp = pLeadExp->m_dwLeadExp;
  756. Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel = PlayerSet.m_cLeadExp.GetLevel(Player[CLIENT_PLAYER_INDEX].m_dwLeadExp, Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel);
  757. Player[CLIENT_PLAYER_INDEX].m_dwNextLevelLeadExp = PlayerSet.m_cLeadExp.GetLevelExp(Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel);
  758. if (dwLevel < Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel)
  759. {
  760. KSystemMessage sMsg;
  761. sprintf(sMsg.szMessage, MSG_LEADER_LEVEL_UP, Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel);
  762. sMsg.eType = SMT_PLAYER;
  763. sMsg.byConfirmType = SMCT_CLICK;
  764. sMsg.byPriority = 1;
  765. sMsg.byParamSize = 0;
  766. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  767. }
  768. }
  769. //-------------------------------------------------------------------------
  770. // 功能:收到服务器发过来的某技能点数
  771. //-------------------------------------------------------------------------
  772. void KProtocolProcess::s2cGetSkillLevel(BYTE* pMsg)
  773. {
  774. int nSkillIndex;
  775. PLAYER_SKILL_LEVEL_SYNC *pSkill = (PLAYER_SKILL_LEVEL_SYNC*)pMsg;
  776. if (pSkill->m_nSkillLevel > MAX_SKILLLEVEL)
  777. return;
  778. nSkillIndex = Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.FindSame(pSkill->m_nSkillID);
  779. Player[CLIENT_PLAYER_INDEX].m_nSkillPoint = pSkill->m_nLeavePoint;
  780. if ( !nSkillIndex )
  781. {
  782. //如果该技能的等级为零,表示新学,直接向客户端填加
  783. if (pSkill->m_nSkillLevel == 0)
  784. {
  785. if ( Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.Add(pSkill->m_nSkillID, 0) == 0 )
  786. return;
  787. }
  788. else
  789. {
  790. if ( Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.Add(pSkill->m_nSkillID, pSkill->m_nSkillLevel) == 0 )
  791. return;
  792. }
  793. }
  794. else
  795. {
  796. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.SetLevel(nSkillIndex, pSkill->m_nSkillLevel);
  797. }
  798. // 通知界面更新技能数据
  799. CoreDataChanged(GDCNI_FIGHT_SKILL_POINT, 0, Player[CLIENT_PLAYER_INDEX].m_nSkillPoint);
  800. KUiSkillData SkillData;
  801. SkillData.uGenre = CGOG_SKILL_FIGHT;
  802. SkillData.uId = pSkill->m_nSkillID;
  803. SkillData.nLevel = pSkill->m_nSkillLevel;
  804. int nSkillPosition = Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList.GetSkillPosition(pSkill->m_nSkillID);
  805. if(nSkillPosition < 0) return;
  806. CoreDataChanged(GDCNI_SKILL_CHANGE, (unsigned int)&SkillData, nSkillPosition);
  807. }
  808. //-------------------------------------------------------------------------
  809. // 功能:收到服务器发来的队友等级变化通知
  810. //-------------------------------------------------------------------------
  811. void KProtocolProcess::s2cGetTeammateLevel(BYTE* pMsg)
  812. {
  813. PLAYER_TEAMMATE_LEVEL_SYNC *pLevel = (PLAYER_TEAMMATE_LEVEL_SYNC*)pMsg;
  814. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  815. {
  816. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  817. return;
  818. }
  819. if ((DWORD)g_Team[0].m_nCaptain == pLevel->m_dwTeammateID)
  820. {
  821. g_Team[0].m_nMemLevel[0] = (DWORD)pLevel->m_btLevel;
  822. return;
  823. }
  824. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  825. {
  826. if ((DWORD)g_Team[0].m_nMember[i] == pLevel->m_dwTeammateID)
  827. {
  828. g_Team[0].m_nMemLevel[i + 1] = (DWORD)pLevel->m_btLevel;
  829. break;
  830. }
  831. }
  832. }
  833. //-------------------------------------------------------------------------
  834. // 功能:收到服务器通知离开门派
  835. //-------------------------------------------------------------------------
  836. void KProtocolProcess::s2cLeaveFaction(BYTE* pMsg)
  837. {
  838. Player[CLIENT_PLAYER_INDEX].m_cFaction.LeaveFaction();
  839. // 改变阵营
  840. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SetCamp(camp_free);
  841. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  842. }
  843. //-------------------------------------------------------------------------
  844. // 功能:收到服务器通知有成员离开(包括自己离开)
  845. //-------------------------------------------------------------------------
  846. void KProtocolProcess::s2cLeaveTeam(BYTE* pMsg)
  847. {
  848. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  849. {
  850. Player[CLIENT_PLAYER_INDEX].m_cTeam.UpdateInterface();
  851. return;
  852. }
  853. PLAYER_LEAVE_TEAM *pLeaveTeam = (PLAYER_LEAVE_TEAM*)pMsg;
  854. // 自己离开
  855. if (pLeaveTeam->m_dwNpcID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  856. {
  857. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag = 0;
  858. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nApplyCaptainID = 0;
  859. g_Team[0].Release();
  860. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].GetMenuState() == PLAYER_MENU_STATE_TEAMOPEN)
  861. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SetMenuState(PLAYER_MENU_STATE_NORMAL);
  862. }
  863. // 别人离开
  864. else
  865. {
  866. g_Team[0].DeleteMember(pLeaveTeam->m_dwNpcID);
  867. }
  868. Player[CLIENT_PLAYER_INDEX].m_cTeam.UpdateInterface();
  869. return;
  870. }
  871. //-------------------------------------------------------------------------
  872. // 功能:收到服务器通知升级
  873. //-------------------------------------------------------------------------
  874. void KProtocolProcess::s2cLevelUp(BYTE* pMsg)
  875. {
  876. Player[CLIENT_PLAYER_INDEX].s2cLevelUp(pMsg);
  877. }
  878. void KProtocolProcess::s2cMoveItem(BYTE* pMsg)
  879. {
  880. PLAYER_MOVE_ITEM_SYNC *pMove = (PLAYER_MOVE_ITEM_SYNC*)pMsg;
  881. ItemPos DownPos, UpPos;
  882. DownPos.nPlace = pMove->m_btDownPos;
  883. DownPos.nX = pMove->m_btDownX;
  884. DownPos.nY = pMove->m_btDownY;
  885. UpPos.nPlace = pMove->m_btUpPos;
  886. UpPos.nX = pMove->m_btUpX;
  887. UpPos.nY = pMove->m_btUpY;
  888. Player[CLIENT_PLAYER_INDEX].m_ItemList.ExchangeItem(&DownPos, &UpPos);
  889. }
  890. void KProtocolProcess::s2cRemoveItem(BYTE* pMsg)
  891. {
  892. ITEM_REMOVE_SYNC *pRemove = (ITEM_REMOVE_SYNC*)pMsg;
  893. int nIdx;
  894. nIdx = Player[CLIENT_PLAYER_INDEX].m_ItemList.SearchID(pRemove->m_ID);
  895. if (nIdx > 0)
  896. {
  897. Player[CLIENT_PLAYER_INDEX].m_ItemList.Remove(nIdx);
  898. Player[CLIENT_PLAYER_INDEX].m_ItemList.UnlockOperation();
  899. }
  900. }
  901. //-------------------------------------------------------------------------
  902. // 功能:收到服务器发来的门派信息
  903. //-------------------------------------------------------------------------
  904. void KProtocolProcess::s2cSetFactionData(BYTE* pMsg)
  905. {
  906. PLAYER_FACTION_DATA *pData = (PLAYER_FACTION_DATA*)pMsg;
  907. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SetCamp(pData->m_btCamp);
  908. Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nCurFaction = (char)pData->m_btCurFaction;
  909. Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nFirstAddFaction = (char)pData->m_btFirstFaction;
  910. Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nAddTimes = pData->m_nAddTimes;
  911. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  912. // Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[0].m_nOpenLevel = pData->m_btNo1SkillOpenLevel;
  913. // Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[1].m_nOpenLevel = pData->m_btNo2SkillOpenLevel;
  914. // if (Player[CLIENT_PLAYER_INDEX].m_cFaction.m_nCurFaction == Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[0].m_nID)
  915. // Player[CLIENT_PLAYER_INDEX].m_cFaction.OpenCurSkillLevel(Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[0].m_nOpenLevel, &Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList);
  916. // else
  917. // Player[CLIENT_PLAYER_INDEX].m_cFaction.OpenCurSkillLevel(Player[CLIENT_PLAYER_INDEX].m_cFaction.m_sSkillOpen[1].m_nOpenLevel, &Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SkillList);
  918. }
  919. //-------------------------------------------------------------------------
  920. // 功能:收到服务器通知队伍状态(队长申请开放、关闭队伍状态时才会收到此信息)
  921. //-------------------------------------------------------------------------
  922. void KProtocolProcess::s2cSetTeamState(BYTE* pMsg)
  923. {
  924. // 客户端数据有误,申请更新数据
  925. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag || Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure != TEAM_CAPTAIN)
  926. {
  927. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  928. return;
  929. }
  930. PLAYER_TEAM_OPEN_CLOSE *pTeamState = (PLAYER_TEAM_OPEN_CLOSE*)pMsg;
  931. Player[CLIENT_PLAYER_INDEX].m_cTeam.ReleaseList();
  932. if (pTeamState->m_btOpenClose)
  933. {
  934. g_Team[0].SetTeamOpen();
  935. KSystemMessage sMsg;
  936. sprintf(sMsg.szMessage, MSG_TEAM_OPEN);
  937. sMsg.eType = SMT_NORMAL;
  938. sMsg.byConfirmType = SMCT_NONE;
  939. sMsg.byPriority = 0;
  940. sMsg.byParamSize = 0;
  941. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  942. }
  943. else
  944. {
  945. g_Team[0].SetTeamClose();
  946. KSystemMessage sMsg;
  947. sprintf(sMsg.szMessage, MSG_TEAM_CLOSE);
  948. sMsg.eType = SMT_NORMAL;
  949. sMsg.byConfirmType = SMCT_NONE;
  950. sMsg.byPriority = 0;
  951. sMsg.byParamSize = 0;
  952. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  953. }
  954. }
  955. //-------------------------------------------------------------------------
  956. // 功能:收到服务器通知队伍状态(队长申请开放、关闭队伍状态时才会收到此信息)
  957. //-------------------------------------------------------------------------
  958. void KProtocolProcess::s2cApplyAddTeam(BYTE* pMsg)
  959. {
  960. Player[CLIENT_PLAYER_INDEX].s2cApplyAddTeam(pMsg);
  961. }
  962. //-------------------------------------------------------------------------
  963. // 功能:收到服务器发来的某个队伍的组队情况,显示之
  964. //-------------------------------------------------------------------------
  965. void KProtocolProcess::s2cShowTeamInfo(BYTE* pMsg)
  966. {
  967. }
  968. void KProtocolProcess::s2cSyncItem(BYTE* pMsg)
  969. {
  970. ITEM_SYNC *pItemSync = (ITEM_SYNC*)pMsg;
  971. int pnMagicParam[6];
  972. for (int i = 0; i < 6; i++)
  973. {
  974. pnMagicParam[i] = pItemSync->m_MagicLevel[i];
  975. }
  976. int nIndex = ItemSet.Add(
  977. pItemSync->m_Genre,
  978. pItemSync->m_Series,
  979. pItemSync->m_Level,
  980. pItemSync->m_Luck,
  981. pItemSync->m_Detail,
  982. pItemSync->m_Particur,
  983. pnMagicParam,
  984. pItemSync->m_Version,
  985. pItemSync->m_RandomSeed);
  986. if (nIndex > 0)
  987. {
  988. Item[nIndex].SetID(pItemSync->m_ID);
  989. Item[nIndex].SetDurability((short)pItemSync->m_Durability);
  990. Player[CLIENT_PLAYER_INDEX].m_ItemList.Add(nIndex, pItemSync->m_btPlace, pItemSync->m_btX, pItemSync->m_btY);
  991. }
  992. Player[CLIENT_PLAYER_INDEX].m_ItemList.UnlockOperation();
  993. }
  994. //-------------------------------------------------------------------------
  995. // 功能:收到服务器发过来的同步money的消息
  996. //-------------------------------------------------------------------------
  997. void KProtocolProcess::s2cSyncMoney(BYTE* pMsg)
  998. {
  999. Player[CLIENT_PLAYER_INDEX].s2cSyncMoney(pMsg);
  1000. }
  1001. void KProtocolProcess::s2cSyncRoleList(BYTE* pMsg)
  1002. {
  1003. ROLE_LIST_SYNC *pSync = (ROLE_LIST_SYNC *)pMsg;
  1004. // TODO: 通过CORESHELL交给界面?
  1005. }
  1006. //-------------------------------------------------------------------------
  1007. // 功能:收到服务器通知有新人加入队伍
  1008. //-------------------------------------------------------------------------
  1009. void KProtocolProcess::s2cTeamAddMember(BYTE* pMsg)
  1010. {
  1011. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag )
  1012. {
  1013. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  1014. return;
  1015. }
  1016. PLAYER_TEAM_ADD_MEMBER *pAddMem = (PLAYER_TEAM_ADD_MEMBER*)pMsg;
  1017. int nMemNum;
  1018. nMemNum = g_Team[0].FindFree();
  1019. if (nMemNum < 0)
  1020. return;
  1021. g_Team[0].m_nMember[nMemNum] = pAddMem->m_dwNpcID;
  1022. g_Team[0].m_nMemLevel[nMemNum + 1] = (DWORD)pAddMem->m_btLevel;
  1023. strcpy(g_Team[0].m_szMemName[nMemNum + 1], pAddMem->m_szName);
  1024. g_Team[0].m_nMemNum++;
  1025. Player[CLIENT_PLAYER_INDEX].m_cTeam.DeleteOneFromApplyList(pAddMem->m_dwNpcID);
  1026. Player[CLIENT_PLAYER_INDEX].m_cTeam.UpdateInterface();
  1027. KSystemMessage sMsg;
  1028. sprintf(sMsg.szMessage, MSG_TEAM_ADD_MEMBER, pAddMem->m_szName);
  1029. sMsg.eType = SMT_NORMAL;
  1030. sMsg.byConfirmType = SMCT_NONE;
  1031. sMsg.byPriority = 0;
  1032. sMsg.byParamSize = 0;
  1033. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1034. }
  1035. //-------------------------------------------------------------------------
  1036. // 功能:收到服务器通知更换队长
  1037. //-------------------------------------------------------------------------
  1038. void KProtocolProcess::s2cTeamChangeCaptain(BYTE* pMsg)
  1039. {
  1040. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  1041. {
  1042. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  1043. return;
  1044. }
  1045. int nLevel, nMemNo;
  1046. char szName[32];
  1047. PLAYER_TEAM_CHANGE_CAPTAIN *pChange = (PLAYER_TEAM_CHANGE_CAPTAIN*)pMsg;
  1048. nMemNo = g_Team[0].FindMemberID(pChange->m_dwCaptainID);
  1049. // 当前队伍数据有误
  1050. if ((DWORD)g_Team[0].m_nCaptain != pChange->m_dwMemberID || nMemNo < 0)
  1051. {
  1052. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  1053. return;
  1054. }
  1055. // 自己被任命为队长
  1056. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID == pChange->m_dwCaptainID)
  1057. {
  1058. KSystemMessage sMsg;
  1059. sprintf(sMsg.szMessage, MSG_TEAM_CHANGE_CAPTAIN_SELF, g_Team[0].m_szMemName[0]);
  1060. sMsg.eType = SMT_TEAM;
  1061. sMsg.byConfirmType = SMCT_UI_TEAM;
  1062. sMsg.byPriority = 3;
  1063. sMsg.byParamSize = 0;
  1064. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1065. }
  1066. else // 别人被任命为队长
  1067. {
  1068. KSystemMessage sMsg;
  1069. sprintf(sMsg.szMessage, MSG_TEAM_CHANGE_CAPTAIN, g_Team[0].m_szMemName[nMemNo + 1]);
  1070. sMsg.eType = SMT_TEAM;
  1071. sMsg.byConfirmType = SMCT_UI_TEAM;
  1072. sMsg.byPriority = 3;
  1073. sMsg.byParamSize = 0;
  1074. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1075. }
  1076. // 更换人员
  1077. nLevel = g_Team[0].m_nMemLevel[0];
  1078. strcpy(szName, g_Team[0].m_szMemName[0]);
  1079. g_Team[0].m_nCaptain = pChange->m_dwCaptainID;
  1080. g_Team[0].m_nMemLevel[0] = g_Team[0].m_nMemLevel[nMemNo + 1];
  1081. strcpy(g_Team[0].m_szMemName[0], g_Team[0].m_szMemName[nMemNo + 1]);
  1082. g_Team[0].m_nMember[nMemNo] = pChange->m_dwMemberID;
  1083. g_Team[0].m_nMemLevel[nMemNo + 1] = nLevel;
  1084. strcpy(g_Team[0].m_szMemName[nMemNo + 1], szName);
  1085. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID == pChange->m_dwCaptainID)
  1086. {
  1087. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_CAPTAIN;
  1088. Player[CLIENT_PLAYER_INDEX].m_cTeam.ReleaseList();
  1089. }
  1090. else if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID == pChange->m_dwMemberID)
  1091. {
  1092. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_MEMBER;
  1093. Player[CLIENT_PLAYER_INDEX].m_cTeam.ReleaseList();
  1094. }
  1095. Player[CLIENT_PLAYER_INDEX].m_cTeam.UpdateInterface();
  1096. }
  1097. //-------------------------------------------------------------------------
  1098. // 功能:收到服务器发来的自己队伍的组队情况,更新相应信息
  1099. //-------------------------------------------------------------------------
  1100. void KProtocolProcess::s2cUpdataSelfTeamInfo(BYTE* pMsg)
  1101. {
  1102. int i;
  1103. PLAYER_SEND_SELF_TEAM_INFO *pSelfInfo = (PLAYER_SEND_SELF_TEAM_INFO*)pMsg;
  1104. // 数据包出错
  1105. if (pSelfInfo->m_dwNpcID[0] == 0)
  1106. return;
  1107. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag = 1;
  1108. Player[CLIENT_PLAYER_INDEX].m_dwLeadExp = pSelfInfo->m_dwLeadExp;
  1109. Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel = PlayerSet.m_cLeadExp.GetLevel(Player[CLIENT_PLAYER_INDEX].m_dwLeadExp);
  1110. Player[CLIENT_PLAYER_INDEX].m_dwNextLevelLeadExp = PlayerSet.m_cLeadExp.GetLevelExp(Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel);
  1111. if (Player[CLIENT_PLAYER_INDEX].m_dwNextLevelLeadExp == 0)
  1112. Player[CLIENT_PLAYER_INDEX].m_dwNextLevelLeadExp = Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel;
  1113. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID == pSelfInfo->m_dwNpcID[0]) // 队长
  1114. {
  1115. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_CAPTAIN;
  1116. }
  1117. else // 队员
  1118. {
  1119. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_MEMBER;
  1120. for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
  1121. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_sApplyList[i].Release();
  1122. }
  1123. g_Team[0].m_nCaptain = pSelfInfo->m_dwNpcID[0];
  1124. if (pSelfInfo->m_btState == 0)
  1125. g_Team[0].SetTeamClose();
  1126. else
  1127. g_Team[0].SetTeamOpen();
  1128. g_Team[0].m_nTeamServerID = pSelfInfo->nTeamServerID;
  1129. g_Team[0].m_nMemLevel[0] = (DWORD)pSelfInfo->m_btLevel[0];
  1130. strcpy(g_Team[0].m_szMemName[0], pSelfInfo->m_szNpcName[0]);
  1131. g_Team[0].m_nMemNum = 0;
  1132. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1133. {
  1134. if (pSelfInfo->m_dwNpcID[i + 1] > 0)
  1135. {
  1136. g_Team[0].m_nMember[i] = pSelfInfo->m_dwNpcID[i + 1];
  1137. g_Team[0].m_nMemLevel[i + 1] = (DWORD)pSelfInfo->m_btLevel[i + 1];
  1138. strcpy(g_Team[0].m_szMemName[i + 1], pSelfInfo->m_szNpcName[i + 1]);
  1139. g_Team[0].m_nMemNum++;
  1140. }
  1141. else
  1142. {
  1143. g_Team[0].m_nMember[i] = -1;
  1144. g_Team[0].m_nMemLevel[i + 1] = 0;
  1145. g_Team[0].m_szMemName[i + 1][0] = 0;
  1146. }
  1147. }
  1148. Player[CLIENT_PLAYER_INDEX].m_cTeam.UpdateInterface();
  1149. }
  1150. void KProtocolProcess::SyncCurNormalData(BYTE* pMsg)
  1151. {
  1152. CURPLAYER_NORMAL_SYNC *pSync = (CURPLAYER_NORMAL_SYNC*)pMsg;
  1153. if (pSync->m_shLife > 0)
  1154. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentLife = pSync->m_shLife;
  1155. else
  1156. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentLife = 0;
  1157. if (pSync->m_shStamina > 0)
  1158. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentStamina = pSync->m_shStamina;
  1159. else
  1160. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentStamina = 0;
  1161. if (pSync->m_shMana > 0)
  1162. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentMana = pSync->m_shMana;
  1163. else
  1164. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentMana = 0;
  1165. // if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Doing == do_sit)
  1166. // {
  1167. // if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentLife >= Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentLifeMax &&
  1168. // Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentMana >= Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentManaMax)
  1169. // {
  1170. // Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SendCommand(do_stand);
  1171. // }
  1172. // }
  1173. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  1174. switch (pSync->m_btTeamData)
  1175. {
  1176. case 0x00:
  1177. if ( Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag )
  1178. {
  1179. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag = 0;
  1180. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  1181. }
  1182. break;
  1183. case 0x03:
  1184. if ( !Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag || Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure != TEAM_CAPTAIN)
  1185. {
  1186. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag = 1;
  1187. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_CAPTAIN;
  1188. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  1189. }
  1190. break;
  1191. case 0x01:
  1192. if ( !Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag || Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure != TEAM_MEMBER)
  1193. {
  1194. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag = 1;
  1195. Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure = TEAM_MEMBER;
  1196. Player[CLIENT_PLAYER_INDEX].ApplySelfTeamInfo();
  1197. }
  1198. break;
  1199. }
  1200. }
  1201. void KProtocolProcess::SyncCurPlayer(BYTE* pMsg)
  1202. {
  1203. Player[CLIENT_PLAYER_INDEX].SyncCurPlayer(pMsg);
  1204. }
  1205. void KProtocolProcess::SyncNpc(BYTE* pMsg)
  1206. {
  1207. NPC_SYNC* NpcSync = (NPC_SYNC *)pMsg;
  1208. /*
  1209. int nRegion = SubWorld[0].FindRegion(NpcSync->RegionID);
  1210. // 如果Region不存在,说明这个包可能有问题,不处理了。
  1211. if (nRegion == -1)
  1212. return;
  1213. */
  1214. int nRegion, nMapX, nMapY, nOffX, nOffY;
  1215. SubWorld[0].Mps2Map(NpcSync->MapX, NpcSync->MapY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
  1216. if (nRegion == -1)
  1217. return;
  1218. int nIdx = NpcSet.SearchID(NpcSync->ID);
  1219. if (!nIdx)
  1220. {
  1221. nIdx = NpcSet.Add(NpcSync->NpcSettingIdx, 0, NpcSync->MapX, NpcSync->MapY);
  1222. Npc[nIdx].m_dwID = NpcSync->ID;
  1223. Npc[nIdx].m_Kind = NpcSync->m_btKind;
  1224. Npc[nIdx].m_Height = 0;
  1225. if (NpcSet.IsNpcRequestExist(NpcSync->ID))
  1226. NpcSet.RemoveNpcRequest(NpcSync->ID);
  1227. }
  1228. else
  1229. {
  1230. if (Npc[nIdx].m_RegionIndex >= 0)
  1231. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].DecRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  1232. Npc[nIdx].m_MapX = nMapX;
  1233. Npc[nIdx].m_MapY = nMapY;
  1234. Npc[nIdx].m_OffX = nOffX;
  1235. Npc[nIdx].m_OffY = nOffY;
  1236. Npc[nIdx].m_NpcSettingIdx = (short)HIWORD(NpcSync->NpcSettingIdx);
  1237. Npc[nIdx].m_Level = LOWORD(NpcSync->NpcSettingIdx);
  1238. if (Npc[nIdx].m_RegionIndex >= 0)
  1239. {
  1240. if (Npc[nIdx].m_RegionIndex != nRegion)
  1241. {
  1242. // zroc change
  1243. SubWorld[0].NpcChangeRegion(SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].m_RegionID, SubWorld[0].m_Region[nRegion].m_RegionID, nIdx);
  1244. Npc[nIdx].m_RegionIndex = nRegion;
  1245. }
  1246. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].AddRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  1247. }
  1248. else
  1249. {
  1250. SubWorld[0].m_Region[nRegion].AddNpc(nIdx);
  1251. Npc[nIdx].m_RegionIndex = nRegion;
  1252. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].AddRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  1253. }
  1254. }
  1255. Npc[nIdx].m_Camp = (NPCCAMP)NpcSync->Camp;
  1256. Npc[nIdx].m_CurrentCamp = (NPCCAMP)NpcSync->CurrentCamp;
  1257. Npc[nIdx].m_Series = NpcSync->m_bySeries;
  1258. // Npc[nIdx].m_NpcEnchant = NpcSync->NpcEnchant;
  1259. Npc[nIdx].m_cGold.SetGoldCurrentType(NpcSync->NpcEnchant);
  1260. if (NpcSync->LifePerCent <= 128)
  1261. Npc[nIdx].m_CurrentLife = (Npc[nIdx].m_CurrentLifeMax * NpcSync->LifePerCent) >> 7 ;
  1262. else
  1263. Npc[nIdx].m_CurrentLife = 0;
  1264. if (Npc[nIdx].m_Doing != do_death || Npc[nIdx].m_Doing != do_revive) // need check later -- spe 03/05/27
  1265. Npc[nIdx].SendCommand((NPCCMD)NpcSync->m_Doing, NpcSync->MapX, NpcSync->MapY);
  1266. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  1267. Npc[nIdx].SetMenuState(NpcSync->m_btMenuState);
  1268. memset(Npc[nIdx].Name, 0, sizeof(Npc[nIdx].Name));
  1269. memcpy(Npc[nIdx].Name, NpcSync->m_szName, NpcSync->m_wLength - (sizeof(NPC_SYNC) - 1 - sizeof(NpcSync->m_szName)));
  1270. }
  1271. void KProtocolProcess::SyncNpcMin(BYTE* pMsg)
  1272. {
  1273. NPC_NORMAL_SYNC* NpcSync = (NPC_NORMAL_SYNC *)pMsg;
  1274. // if (NpcSync->ID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  1275. // return;
  1276. if (NpcSync->Doing == do_revive || NpcSync->Doing == do_death)
  1277. return;
  1278. int nIdx = NpcSet.SearchID(NpcSync->ID);
  1279. if (!nIdx)
  1280. {
  1281. // 向服务器请求同步这个NPC的全部数据
  1282. if (!NpcSet.IsNpcRequestExist(NpcSync->ID))
  1283. {
  1284. SendClientCmdRequestNpc(NpcSync->ID);
  1285. NpcSet.InsertNpcRequest(NpcSync->ID);
  1286. }
  1287. }
  1288. else
  1289. {
  1290. // int nRegion = SubWorld[0].FindRegion(NpcSync->RegionID);
  1291. int nRegion, nMapX, nMapY, nOffX, nOffY;
  1292. SubWorld[0].Mps2Map(NpcSync->MapX, NpcSync->MapY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
  1293. if (Npc[nIdx].m_RegionIndex == -1 && nIdx != Player[CLIENT_PLAYER_INDEX].m_nIndex)
  1294. {
  1295. if (nRegion == -1)
  1296. {
  1297. return;
  1298. }
  1299. else
  1300. {
  1301. Npc[nIdx].m_MapX = nMapX;
  1302. Npc[nIdx].m_MapY = nMapY;
  1303. Npc[nIdx].m_OffX = nOffX;
  1304. Npc[nIdx].m_OffY = nOffY;
  1305. Npc[nIdx].m_RegionIndex = nRegion;
  1306. Npc[nIdx].m_dwRegionID = SubWorld[0].m_Region[nRegion].m_RegionID;
  1307. SubWorld[0].m_Region[nRegion].AddNpc(nIdx);
  1308. SubWorld[0].m_Region[nRegion].AddRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  1309. }
  1310. if (NpcSync->Doing == do_stand)
  1311. Npc[nIdx].ProcNetCommand(do_stand);
  1312. }
  1313. else
  1314. {
  1315. if (Npc[nIdx].m_RegionIndex != nRegion && nIdx != Player[CLIENT_PLAYER_INDEX].m_nIndex)
  1316. {
  1317. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].RemoveNpc(nIdx);
  1318. SubWorld[0].m_Region[Npc[nIdx].m_RegionIndex].DecRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  1319. Npc[nIdx].m_MapX = nMapX;
  1320. Npc[nIdx].m_MapY = nMapY;
  1321. Npc[nIdx].m_OffX = nOffX;
  1322. Npc[nIdx].m_OffY = nOffY;
  1323. Npc[nIdx].m_RegionIndex = nRegion;
  1324. if (nRegion >= 0)
  1325. {
  1326. SubWorld[0].m_Region[nRegion].AddNpc(nIdx);
  1327. Npc[nIdx].m_dwRegionID = SubWorld[0].m_Region[nRegion].m_RegionID;
  1328. SubWorld[0].m_Region[nRegion].AddRef(Npc[nIdx].m_MapX, Npc[nIdx].m_MapY, obj_npc);
  1329. }
  1330. }
  1331. }
  1332. if (nIdx != Player[CLIENT_PLAYER_INDEX].m_nIndex) // 非玩家
  1333. {
  1334. int nOldLife = Npc[nIdx].m_CurrentLife;
  1335. if (NpcSync->LifePerCent <= 128)
  1336. {
  1337. Npc[nIdx].m_CurrentLife = (Npc[nIdx].m_CurrentLifeMax * NpcSync->LifePerCent) >> 7;
  1338. }
  1339. else
  1340. {
  1341. Npc[nIdx].m_CurrentLife = 0;
  1342. }
  1343. // 冒血处理
  1344. if (Npc[nIdx].m_Kind == kind_normal)
  1345. {
  1346. Npc[nIdx].SetBlood(nOldLife - Npc[nIdx].m_CurrentLife);
  1347. }
  1348. Npc[nIdx].m_CurrentCamp = NpcSync->Camp;
  1349. }
  1350. Npc[nIdx].m_FreezeState.nTime = NpcSync->State & STATE_FREEZE;
  1351. Npc[nIdx].m_PoisonState.nTime = NpcSync->State & STATE_POISON;
  1352. Npc[nIdx].m_ConfuseState.nTime =NpcSync->State & STATE_CONFUSE;
  1353. Npc[nIdx].m_StunState.nTime = NpcSync->State & STATE_STUN;
  1354. Npc[nIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  1355. }
  1356. }
  1357. //-------------------------------------------------------------------------
  1358. // 功能:收到服务器消息同步本玩家npc数据
  1359. //-------------------------------------------------------------------------
  1360. void KProtocolProcess::SyncNpcMinPlayer(BYTE* pMsg)
  1361. {
  1362. NPC_PLAYER_TYPE_NORMAL_SYNC *pSync = (NPC_PLAYER_TYPE_NORMAL_SYNC*)pMsg;
  1363. _ASSERT(pSync->m_dwNpcID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID);
  1364. if (pSync->m_dwNpcID != Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  1365. return;
  1366. int nRegion, nMapX, nMapY, nOffX, nOffY, nNpcIdx;
  1367. SubWorld[0].Mps2Map(pSync->m_dwMapX, pSync->m_dwMapY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
  1368. nNpcIdx = Player[CLIENT_PLAYER_INDEX].m_nIndex;
  1369. // 切换地图了,主角的RegionIndex为-1
  1370. if (Npc[nNpcIdx].m_RegionIndex == -1)
  1371. {
  1372. //nRegionIdx = SubWorld[0].FindRegion(pSync->m_nRegionID);
  1373. if (nRegion < 0)
  1374. {
  1375. // 刚刚换的地图,这个时候应该能找得到region,如果找不到,说明数据包可能出错了
  1376. // _ASSERT(0);
  1377. return;
  1378. }
  1379. Npc[nNpcIdx].m_RegionIndex = nRegion;
  1380. Npc[nNpcIdx].m_dwRegionID = SubWorld[0].m_Region[nRegion].m_RegionID;
  1381. //pSync->m_nRegionID;
  1382. SubWorld[0].NpcChangeRegion(-1, SubWorld[0].m_Region[nRegion].m_RegionID, nNpcIdx);
  1383. SubWorld[0].m_Region[nRegion].AddRef(nMapX, nMapY, obj_npc);
  1384. Npc[nNpcIdx].m_MapX = nMapX;
  1385. Npc[nNpcIdx].m_MapY = nMapY;
  1386. Npc[nNpcIdx].m_OffX = pSync->m_wOffX;
  1387. Npc[nNpcIdx].m_OffY = pSync->m_wOffY;
  1388. memset(&Npc[nNpcIdx].m_sSyncPos, 0, sizeof(Npc[nNpcIdx].m_sSyncPos));
  1389. Npc[nNpcIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  1390. return;
  1391. }
  1392. // 跳太远,超出9屏范围
  1393. //nRegionIdx = SubWorld[0].FindRegion(pSync->m_nRegionID);
  1394. if (nRegion == -1)
  1395. {
  1396. SubWorld[0].m_Region[Npc[nNpcIdx].m_RegionIndex].DecRef(Npc[nNpcIdx].m_MapX, Npc[nNpcIdx].m_MapY, obj_npc);
  1397. int nRegionX = pSync->m_dwMapX / (SubWorld[0].m_nCellWidth * SubWorld[0].m_nRegionWidth);
  1398. int nRegionY = pSync->m_dwMapY / (SubWorld[0].m_nCellHeight * SubWorld[0].m_nRegionHeight);
  1399. DWORD dwRegionID = MAKELONG(nRegionX, nRegionY);
  1400. SubWorld[0].LoadMap(SubWorld[0].m_SubWorldID, dwRegionID);
  1401. // SubWorld[0].LoadMap(SubWorld[0].m_SubWorldID, pSync->m_nRegionID);
  1402. nRegion = SubWorld[0].FindRegion(dwRegionID);
  1403. _ASSERT(nRegion >= 0);
  1404. Npc[nNpcIdx].m_RegionIndex = nRegion;
  1405. Npc[nNpcIdx].m_dwRegionID = dwRegionID;//pSync->m_nRegionID;
  1406. SubWorld[0].NpcChangeRegion(-1, SubWorld[0].m_Region[nRegion].m_RegionID, nNpcIdx);
  1407. SubWorld[0].Mps2Map(pSync->m_dwMapX, pSync->m_dwMapY, &nRegion, &nMapX, &nMapY, &nOffX, &nOffY);
  1408. Npc[nNpcIdx].m_MapX = nMapX;
  1409. Npc[nNpcIdx].m_MapY = nMapY;
  1410. Npc[nNpcIdx].m_OffX = pSync->m_wOffX;
  1411. Npc[nNpcIdx].m_OffY = pSync->m_wOffY;
  1412. SubWorld[0].m_Region[Npc[nNpcIdx].m_RegionIndex].AddRef(Npc[nNpcIdx].m_MapX, Npc[nNpcIdx].m_MapY, obj_npc);
  1413. memset(&Npc[nNpcIdx].m_sSyncPos, 0, sizeof(Npc[nNpcIdx].m_sSyncPos));
  1414. Npc[nNpcIdx].m_SyncSignal = SubWorld[0].m_dwCurrentTime;
  1415. return;
  1416. }
  1417. BYTE byBarrier = SubWorld[0].m_Region[Npc[nNpcIdx].m_RegionIndex].GetBarrier(Npc[nNpcIdx].m_MapX, Npc[nNpcIdx].m_MapY, Npc[nNpcIdx].m_OffX, Npc[nNpcIdx].m_OffY);
  1418. if (0 != byBarrier && Obstacle_JumpFly != byBarrier)
  1419. {
  1420. g_DebugLog("[Barrier]Player in Barrier");
  1421. }
  1422. }
  1423. //-------------------------------------------------------------------------
  1424. // 功能:收到服务器消息添加一个obj
  1425. //-------------------------------------------------------------------------
  1426. void KProtocolProcess::SyncObjectAdd(BYTE* pMsg)
  1427. {
  1428. OBJ_ADD_SYNC *pObjSyncAdd = (OBJ_ADD_SYNC*)pMsg;
  1429. int nObjIndex;
  1430. KObjItemInfo sInfo;
  1431. nObjIndex = ObjSet.FindID(pObjSyncAdd->m_nID);
  1432. if (nObjIndex > 0)
  1433. return;
  1434. sInfo.m_nItemID = pObjSyncAdd->m_nItemID;
  1435. sInfo.m_nItemWidth = pObjSyncAdd->m_btItemWidth;
  1436. sInfo.m_nItemHeight = pObjSyncAdd->m_btItemHeight;
  1437. sInfo.m_nMoneyNum = pObjSyncAdd->m_nMoneyNum;
  1438. sInfo.m_nColorID = pObjSyncAdd->m_btColorID;
  1439. sInfo.m_nMovieFlag = ((pObjSyncAdd->m_btFlag & 0x02) > 0 ? 1 : 0);
  1440. sInfo.m_nSoundFlag = ((pObjSyncAdd->m_btFlag & 0x01) > 0 ? 1 : 0);
  1441. memset(sInfo.m_szName, 0, sizeof(sInfo.m_szName));
  1442. memcpy(sInfo.m_szName, pObjSyncAdd->m_szName, pObjSyncAdd->m_wLength + 1 + sizeof(pObjSyncAdd->m_szName) - sizeof(OBJ_ADD_SYNC));
  1443. nObjIndex = ObjSet.ClientAdd(
  1444. pObjSyncAdd->m_nID,
  1445. pObjSyncAdd->m_nDataID,
  1446. pObjSyncAdd->m_btState,
  1447. pObjSyncAdd->m_btDir,
  1448. pObjSyncAdd->m_wCurFrame,
  1449. pObjSyncAdd->m_nXpos,
  1450. pObjSyncAdd->m_nYpos,
  1451. sInfo);
  1452. #ifdef WAIGUA_ZROC
  1453. if (nObjIndex <= 0)
  1454. return;
  1455. PLAYER_PICKUP_ITEM_COMMAND sPickUp;
  1456. if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
  1457. {
  1458. // sPickUp.ProtocolType = c2s_playerpickupitem;
  1459. // sPickUp.m_nObjID = Object[nObjIndex].m_nID;
  1460. // sPickUp.m_btPosType = 0;
  1461. // sPickUp.m_btPosX = 0;
  1462. // sPickUp.m_btPosY = 0;
  1463. // if (g_pClient)
  1464. // g_pClient->SendPackToServer(&sPickUp, sizeof(PLAYER_PICKUP_ITEM_COMMAND));
  1465. }
  1466. else if (Object[nObjIndex].m_nKind == Obj_Kind_Item)
  1467. {
  1468. ItemPos sItemPos;
  1469. if ( FALSE == Player[CLIENT_PLAYER_INDEX].m_ItemList.SearchPosition(Object[nObjIndex].m_nItemWidth, Object[nObjIndex].m_nItemHeight, &sItemPos) )
  1470. return;
  1471. sPickUp.ProtocolType = c2s_playerpickupitem;
  1472. sPickUp.m_nObjID = Object[nObjIndex].m_nID;
  1473. sPickUp.m_btPosType = sItemPos.nPlace;
  1474. sPickUp.m_btPosX = sItemPos.nX;
  1475. sPickUp.m_btPosY = sItemPos.nY;
  1476. if (g_pClient)
  1477. g_pClient->SendPackToServer(&sPickUp, sizeof(PLAYER_PICKUP_ITEM_COMMAND));
  1478. }
  1479. #endif
  1480. }
  1481. //-------------------------------------------------------------------------
  1482. // 功能:收到服务器消息更新某个obj方向
  1483. //-------------------------------------------------------------------------
  1484. void KProtocolProcess::SyncObjectDir(BYTE* pMsg)
  1485. {
  1486. OBJ_SYNC_DIR *pObjSyncDir = (OBJ_SYNC_DIR*)pMsg;
  1487. int nObjIndex;
  1488. nObjIndex = ObjSet.FindID(pObjSyncDir->m_nID);
  1489. if (nObjIndex <= 0)
  1490. {
  1491. // 向服务器发添加请求
  1492. OBJ_CLIENT_SYNC_ADD sObjClientSyncAdd;
  1493. sObjClientSyncAdd.ProtocolType = c2s_requestobj;
  1494. sObjClientSyncAdd.m_nID = pObjSyncDir->m_nID;
  1495. if (g_pClient)
  1496. g_pClient->SendPackToServer(&sObjClientSyncAdd, sizeof(sObjClientSyncAdd));
  1497. }
  1498. else
  1499. { // 同步方向
  1500. Object[nObjIndex].SetDir(pObjSyncDir->m_btDir);
  1501. }
  1502. }
  1503. //-------------------------------------------------------------------------
  1504. // 功能:收到服务器消息删除某个obj
  1505. //-------------------------------------------------------------------------
  1506. void KProtocolProcess::SyncObjectRemove(BYTE* pMsg)
  1507. {
  1508. OBJ_SYNC_REMOVE *pObjSyncRemove = (OBJ_SYNC_REMOVE*)pMsg;
  1509. int nObjIndex;
  1510. nObjIndex = ObjSet.FindID(pObjSyncRemove->m_nID);
  1511. if (nObjIndex > 0)
  1512. { // 删除
  1513. Object[nObjIndex].Remove(pObjSyncRemove->m_btSoundFlag);
  1514. }
  1515. }
  1516. //-------------------------------------------------------------------------
  1517. // 功能:收到服务器消息更新某个obj状态
  1518. //-------------------------------------------------------------------------
  1519. void KProtocolProcess::SyncObjectState(BYTE* pMsg)
  1520. {
  1521. OBJ_SYNC_STATE *pObjSyncState = (OBJ_SYNC_STATE*)pMsg;
  1522. int nObjIndex;
  1523. nObjIndex = ObjSet.FindID(pObjSyncState->m_nID);
  1524. if (nObjIndex <= 0)
  1525. {
  1526. // 向服务器发添加请求
  1527. OBJ_CLIENT_SYNC_ADD sObjClientSyncAdd;
  1528. sObjClientSyncAdd.ProtocolType = c2s_requestobj;
  1529. sObjClientSyncAdd.m_nID = pObjSyncState->m_nID;
  1530. if (g_pClient)
  1531. g_pClient->SendPackToServer(&sObjClientSyncAdd, sizeof(sObjClientSyncAdd));
  1532. }
  1533. else
  1534. { // 同步状态
  1535. if (Object[nObjIndex].m_nRegionIdx == -1)
  1536. {
  1537. int nRegion;
  1538. nRegion = SubWorld[0].FindRegion(Object[nObjIndex].m_nBelongRegion);
  1539. if (nRegion >= 0)
  1540. {
  1541. Object[nObjIndex].m_nRegionIdx = nRegion;
  1542. SubWorld[0].m_Region[nRegion].AddObj(nObjIndex);
  1543. }
  1544. }
  1545. Object[nObjIndex].SetState(pObjSyncState->m_btState);
  1546. }
  1547. }
  1548. //-------------------------------------------------------------------------
  1549. // 功能:收到服务器消息同步某个 trap 类 obj 的数据
  1550. //-------------------------------------------------------------------------
  1551. void KProtocolProcess::SyncObjectTrap(BYTE* pMsg)
  1552. {
  1553. OBJ_SYNC_TRAP_ACT *pObjTrapSync = (OBJ_SYNC_TRAP_ACT*)pMsg;
  1554. int nObjIndex;
  1555. nObjIndex = ObjSet.FindID(pObjTrapSync->m_nID);
  1556. if (nObjIndex <= 0)
  1557. {
  1558. // 向服务器发添加请求
  1559. OBJ_CLIENT_SYNC_ADD sObjClientSyncAdd;
  1560. sObjClientSyncAdd.ProtocolType = c2s_requestobj;
  1561. sObjClientSyncAdd.m_nID = pObjTrapSync->m_nID;
  1562. if (g_pClient)
  1563. g_pClient->SendPackToServer(&sObjClientSyncAdd, sizeof(sObjClientSyncAdd));
  1564. }
  1565. else
  1566. {
  1567. Object[nObjIndex].m_nState = OBJ_TRAP_STATE_ACTING;
  1568. Object[nObjIndex].m_cImage.SetDirStart();
  1569. Object[nObjIndex].m_cSkill.m_nTarX = pObjTrapSync->m_nTarX;
  1570. Object[nObjIndex].m_cSkill.m_nTarY = pObjTrapSync->m_nTarY;
  1571. }
  1572. }
  1573. void KProtocolProcess::SyncPlayer(BYTE* pMsg)
  1574. {
  1575. PLAYER_SYNC* pPlaySync = (PLAYER_SYNC *)pMsg;
  1576. int nIdx = NpcSet.SearchID(pPlaySync->ID);
  1577. Npc[nIdx].m_ArmorType = pPlaySync->ArmorType;
  1578. Npc[nIdx].m_AttackSpeed = pPlaySync->AttackSpeed;
  1579. Npc[nIdx].m_CastSpeed = pPlaySync->CastSpeed;
  1580. Npc[nIdx].m_HelmType = pPlaySync->HelmType;
  1581. Npc[nIdx].m_HorseType = (char)pPlaySync->HorseType;
  1582. Npc[nIdx].m_CurrentRunSpeed = pPlaySync->RunSpeed;
  1583. Npc[nIdx].m_CurrentWalkSpeed = pPlaySync->WalkSpeed;
  1584. Npc[nIdx].m_WeaponType = pPlaySync->WeaponType;
  1585. Npc[nIdx].m_Kind = kind_player;
  1586. Npc[nIdx].m_btRankId = pPlaySync->RankID;
  1587. if (Npc[nIdx].m_HorseType == -1)
  1588. Npc[nIdx].m_bRideHorse = FALSE;
  1589. else
  1590. Npc[nIdx].m_bRideHorse = TRUE;
  1591. if (pPlaySync->m_btSomeFlag & 0x01)
  1592. Npc[nIdx].m_nPKFlag = 1;
  1593. else
  1594. Npc[nIdx].m_nPKFlag = 0;
  1595. if (pPlaySync->m_btSomeFlag & 0x02)
  1596. Npc[nIdx].m_FightMode = 1;
  1597. else
  1598. Npc[nIdx].m_FightMode = 0;
  1599. if (pPlaySync->m_btSomeFlag & 0x04)
  1600. Npc[nIdx].SetSleepMode(1);
  1601. else
  1602. Npc[nIdx].SetSleepMode(0);
  1603. }
  1604. void KProtocolProcess::SyncPlayerMin(BYTE* pMsg)
  1605. {
  1606. PLAYER_NORMAL_SYNC* pPlaySync = (PLAYER_NORMAL_SYNC *)pMsg;
  1607. int nIdx = NpcSet.SearchID(pPlaySync->ID);
  1608. Npc[nIdx].m_AttackSpeed = pPlaySync->AttackSpeed;
  1609. Npc[nIdx].m_CastSpeed = pPlaySync->CastSpeed;
  1610. Npc[nIdx].m_CurrentRunSpeed = pPlaySync->RunSpeed;
  1611. Npc[nIdx].m_CurrentWalkSpeed = pPlaySync->WalkSpeed;
  1612. Npc[nIdx].m_HelmType = pPlaySync->HelmType;
  1613. Npc[nIdx].m_ArmorType = pPlaySync->ArmorType;
  1614. Npc[nIdx].m_HorseType = (char)pPlaySync->HorseType;
  1615. Npc[nIdx].m_WeaponType = pPlaySync->WeaponType;
  1616. Npc[nIdx].m_Kind = kind_player;
  1617. Npc[nIdx].m_btRankId = pPlaySync->RankID;
  1618. if (Npc[nIdx].m_HorseType == -1)
  1619. Npc[nIdx].m_bRideHorse = FALSE;
  1620. else
  1621. Npc[nIdx].m_bRideHorse = TRUE;
  1622. if (pPlaySync->m_btSomeFlag & 0x01)
  1623. Npc[nIdx].m_nPKFlag = 1;
  1624. else
  1625. Npc[nIdx].m_nPKFlag = 0;
  1626. if (pPlaySync->m_btSomeFlag & 0x02)
  1627. Npc[nIdx].m_FightMode = 1;
  1628. else
  1629. Npc[nIdx].m_FightMode = 0;
  1630. if (pPlaySync->m_btSomeFlag & 0x04)
  1631. Npc[nIdx].SetSleepMode(1);
  1632. else
  1633. Npc[nIdx].SetSleepMode(0);
  1634. if (pPlaySync->m_btSomeFlag & 0x08)
  1635. Npc[nIdx].m_nTongFlag = 1;
  1636. else
  1637. Npc[nIdx].m_nTongFlag = 0;
  1638. }
  1639. void KProtocolProcess::SyncScriptAction(BYTE* pMsg)
  1640. {
  1641. Player[CLIENT_PLAYER_INDEX].OnScriptAction((PLAYER_SCRIPTACTION_SYNC *)pMsg);
  1642. }
  1643. void KProtocolProcess::SyncWorld(BYTE* pMsg)
  1644. {
  1645. WORLD_SYNC *WorldSync = (WORLD_SYNC *)pMsg;
  1646. if (Player[CLIENT_PLAYER_INDEX].m_nIndex > 0)
  1647. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SendCommand(do_stand);
  1648. if (SubWorld[0].m_SubWorldID != WorldSync->SubWorld)
  1649. {
  1650. SubWorld[0].LoadMap(WorldSync->SubWorld, WorldSync->Region);
  1651. /* SubWorld[0].m_Region[0].Load(WorldSync->SubWorld, WorldSync->Region);
  1652. SubWorld[0].m_Region[0].Init(SubWorld[0].m_nRegionWidth, SubWorld[0].m_nRegionHeight);
  1653. for (int i = 0; i < 8; i++)
  1654. {
  1655. if (SubWorld[0].m_Region[0].m_nConRegionID[i] == -1)
  1656. continue;
  1657. SubWorld[0].m_Region[i+1].Load(WorldSync->SubWorld, SubWorld[0].m_Region[0].m_nConRegionID[i]);
  1658. SubWorld[0].m_Region[i+1].Init(SubWorld[0].m_nRegionWidth, SubWorld[0].m_nRegionHeight);
  1659. }*/
  1660. }
  1661. if (SubWorld[0].m_dwCurrentTime > WorldSync->Frame)
  1662. {
  1663. // 客户端快了,减速处理,或者是Lag引起的旧消息,需要处理
  1664. }
  1665. else if (SubWorld[0].m_dwCurrentTime < WorldSync->Frame)
  1666. {
  1667. // 客户端慢了,加速处理
  1668. }
  1669. SubWorld[0].m_dwCurrentTime = WorldSync->Frame;
  1670. // 同步天气
  1671. SubWorld[0].m_nWeather = WorldSync->Weather;
  1672. g_ScenePlace.ChangeWeather(WorldSync->Weather);
  1673. }
  1674. //-------------------------------------------------------------------------
  1675. // 功能:收到服务器消息某玩家终止了与本客户端的好友关系
  1676. //-------------------------------------------------------------------------
  1677. void KProtocolProcess::s2cChatDeleteFriend(BYTE* pMsg)
  1678. {
  1679. CHAT_DELETE_FRIEND_SYNC *pDelete = (CHAT_DELETE_FRIEND_SYNC*)pMsg;
  1680. CChatFriend *pFriend;
  1681. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  1682. {
  1683. pFriend = (CChatFriend*)Player[CLIENT_PLAYER_INDEX].m_cChat.m_cFriendTeam[i].m_cEveryOne.GetHead();
  1684. while (pFriend)
  1685. {
  1686. if (pFriend->m_dwID == pDelete->m_dwID)
  1687. {
  1688. pFriend->Remove();
  1689. Player[CLIENT_PLAYER_INDEX].m_cChat.m_cFriendTeam[i].m_nFriendNo--;
  1690. // 通知界面 某玩家终止了与本客户端的好友关系
  1691. // CoreDataChanged(GDCNI_CHAT_GROUP, 0, 0);
  1692. CoreDataChanged(GDCNI_CHAT_FRIEND, 0, i);
  1693. KSystemMessage sMsg;
  1694. sprintf(sMsg.szMessage, MSG_CHAT_DELETED_FRIEND, pFriend->m_szName);
  1695. sMsg.eType = SMT_NORMAL;
  1696. sMsg.byConfirmType = SMCT_NONE;
  1697. sMsg.byPriority = 0;
  1698. sMsg.byParamSize = 0;
  1699. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1700. delete pFriend;
  1701. return;
  1702. }
  1703. pFriend = (CChatFriend*)pFriend->GetNext();
  1704. }
  1705. }
  1706. }
  1707. //-------------------------------------------------------------------------
  1708. // 功能:收到服务器通知某聊天好友下线
  1709. //-------------------------------------------------------------------------
  1710. void KProtocolProcess::s2cChatFriendOffLine(BYTE* pMsg)
  1711. {
  1712. CHAT_FRIEND_OFFLINE_SYNC *pSync = (CHAT_FRIEND_OFFLINE_SYNC*)pMsg;
  1713. Player[CLIENT_PLAYER_INDEX].m_cChat.GetMsgOffLine(pSync->m_dwID);
  1714. }
  1715. void KProtocolProcess::s2cSyncAllSkill(BYTE * pMsg)
  1716. {
  1717. SKILL_SEND_ALL_SYNC * pSync = (SKILL_SEND_ALL_SYNC*) pMsg;
  1718. int nSkillCount = (pSync->m_wProtocolLong - 2) / sizeof(SKILL_SEND_ALL_SYNC_DATA);
  1719. int nNpcIndex = Player[CLIENT_PLAYER_INDEX].m_nIndex;
  1720. KSkill * pOrdinSkill = NULL;
  1721. Npc[nNpcIndex].m_SkillList.Clear();
  1722. for (int i = 0; i < nSkillCount; i ++)
  1723. {
  1724. if (pSync->m_sAllSkill[i].SkillId)
  1725. {
  1726. // pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(pSync->m_sAllSkill[i].SkillId, pSync->m_sAllSkill[i].SkillLevel);
  1727. // if (!pOrdinSkill) 
  1728. //              continue;
  1729. Npc[nNpcIndex].m_SkillList.Add(
  1730. pSync->m_sAllSkill[i].SkillId,
  1731. pSync->m_sAllSkill[i].SkillLevel,
  1732. 0
  1733.             );
  1734. }
  1735. }
  1736. }
  1737. void KProtocolProcess::SyncEnd(BYTE* pMsg)
  1738. {
  1739. BYTE SyncEnd = (BYTE)c2s_syncend;
  1740. if (g_pClient)
  1741. g_pClient->SendPackToServer(&SyncEnd, sizeof(BYTE));
  1742. Player[CLIENT_PLAYER_INDEX].SetDefaultImmedSkill();
  1743. g_DebugLog("[TRACE]SyncEnd to Server");
  1744. CoreDataChanged(GDCNI_GAME_START, 0, 0);
  1745. // g_bPingReply = TRUE;
  1746. // 设定聊天订阅频道
  1747. // Player[CLIENT_PLAYER_INDEX].m_cChat.LoadTeamName(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  1748. // Player[CLIENT_PLAYER_INDEX].m_cChat.SaveTeamInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  1749. // Player[CLIENT_PLAYER_INDEX].m_cChat.LoadTakeChannelInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  1750. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SetInstantSpr(enumINSTANT_STATE_LOGIN);
  1751. // 开始播音乐
  1752. g_SubWorldSet.m_cMusic.Start(SubWorld[0].m_SubWorldID, SubWorld[0].m_dwCurrentTime, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_FightMode);
  1753. // PK初始化
  1754. Player[CLIENT_PLAYER_INDEX].m_cPK.Init();
  1755. }
  1756. void KProtocolProcess::s2cTradeChangeState(BYTE* pMsg)
  1757. {
  1758. Player[CLIENT_PLAYER_INDEX].s2cTradeChangeState(pMsg);
  1759. }
  1760. void KProtocolProcess::s2cNpcSetMenuState(BYTE* pMsg)
  1761. {
  1762. NPC_SET_MENU_STATE_SYNC *pState = (NPC_SET_MENU_STATE_SYNC*)pMsg;
  1763. int nNpc;
  1764. if (pState->m_dwID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  1765. {
  1766. nNpc = Player[CLIENT_PLAYER_INDEX].m_nIndex;
  1767. if (pState->m_btState == PLAYER_MENU_STATE_TRADEOPEN)
  1768. {
  1769. KSystemMessage sMsg;
  1770. sprintf(sMsg.szMessage, MSG_TRADE_STATE_OPEN);
  1771. sMsg.eType = SMT_NORMAL;
  1772. sMsg.byConfirmType = SMCT_NONE;
  1773. sMsg.byPriority = 0;
  1774. sMsg.byParamSize = 0;
  1775. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1776. }
  1777. else if (pState->m_btState == PLAYER_MENU_STATE_NORMAL)
  1778. {
  1779. if (Npc[nNpc].GetMenuState() == PLAYER_MENU_STATE_TRADEOPEN)
  1780. {
  1781. KSystemMessage sMsg;
  1782. sprintf(sMsg.szMessage, MSG_TRADE_STATE_CLOSE);
  1783. sMsg.eType = SMT_NORMAL;
  1784. sMsg.byConfirmType = SMCT_NONE;
  1785. sMsg.byPriority = 0;
  1786. sMsg.byParamSize = 0;
  1787. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. nNpc = NpcSet.SearchID(pState->m_dwID);
  1794. if (nNpc == 0)
  1795. return;
  1796. }
  1797. if (pState->m_wLength > sizeof(NPC_SET_MENU_STATE_SYNC) - 1 - sizeof(pState->m_szSentence))
  1798. Npc[nNpc].SetMenuState(pState->m_btState, pState->m_szSentence, pState->m_wLength - (sizeof(NPC_SET_MENU_STATE_SYNC) - 1 - sizeof(pState->m_szSentence)));
  1799. else
  1800. Npc[nNpc].SetMenuState(pState->m_btState);
  1801. }
  1802. void KProtocolProcess::s2cTradeMoneySync(BYTE* pMsg)
  1803. {
  1804. Player[CLIENT_PLAYER_INDEX].s2cTradeMoneySync(pMsg);
  1805. }
  1806. void KProtocolProcess::s2cTradeDecision(BYTE* pMsg)
  1807. {
  1808. Player[CLIENT_PLAYER_INDEX].s2cTradeDecision(pMsg);
  1809. Player[CLIENT_PLAYER_INDEX].m_ItemList.UnlockOperation();
  1810. }
  1811. void KProtocolProcess::s2cUpdateNpcState(BYTE * pMsg)
  1812. {
  1813. NPC_SYNC_STATEINFO * pInfo = (NPC_SYNC_STATEINFO*) pMsg;
  1814. int nIndex = NpcSet.SearchID(pInfo->m_ID);
  1815. if (nIndex > 0 && !Npc[nIndex].IsPlayer() && Npc[nIndex].m_RegionIndex >= 0)
  1816. {
  1817. Npc[nIndex].SetNpcState(pInfo->m_btStateInfo);
  1818. }
  1819. }
  1820. void KProtocolProcess::s2cTeamInviteAdd(BYTE * pMsg)
  1821. {
  1822. Player[CLIENT_PLAYER_INDEX].m_cTeam.ReceiveInvite((TEAM_INVITE_ADD_SYNC*)pMsg);
  1823. }
  1824. void KProtocolProcess::s2cTradePressOkSync(BYTE * pMsg)
  1825. {
  1826. TRADE_STATE_SYNC *pPress = (TRADE_STATE_SYNC*)pMsg;
  1827. Player[CLIENT_PLAYER_INDEX].m_cTrade.SetTradeState(pPress->m_btSelfLock, pPress->m_btDestLock, pPress->m_btSelfOk, pPress->m_btDestOk);
  1828. }
  1829. void KProtocolProcess::s2cDirectlyCastSkill(BYTE * pMsg)
  1830. {
  1831. DWORD dwNpcID;
  1832. int nSkillID, nSkillLevel;
  1833. DWORD MapX, MapY;
  1834. dwNpcID = *(DWORD *)&pMsg[1];
  1835. nSkillID = *(int *)&pMsg[5];
  1836. nSkillLevel = *(int *)&pMsg[9];
  1837. MapX = *(int *)&pMsg[13];
  1838. MapY = *(int *)&pMsg[17];
  1839. //当指定某个目标时(MapX == -1),MapY为目标的NpcdwID,需要转换成本地的NpcIndex才行
  1840. if (MapX == -1)
  1841. {
  1842. if (MapY < 0 ) return;
  1843. MapY = NpcSet.SearchID(MapY);
  1844. if (MapY == 0) return;
  1845. if (Npc[MapY].m_RegionIndex < 0)
  1846. return;
  1847. int nX, nY;
  1848. nX = Npc[MapY].m_MapX;
  1849. nY = Npc[MapY].m_MapY;
  1850. SubWorld[0].Map2Mps(Npc[MapY].m_RegionIndex, nX, nY, 0, 0, (int *)&MapX, (int *)&MapY);
  1851. }
  1852. int nIdx = NpcSet.SearchID(dwNpcID);
  1853. /// if (Player[CLIENT_PLAYER_INDEX].ConformIdx(nIdx))
  1854. {
  1855. _ASSERT (nSkillID > 0 && nSkillLevel > 0);
  1856. KSkill * pOrdinSkill = (KSkill *) g_SkillManager.GetSkill(nSkillID, nSkillLevel);
  1857. if (!pOrdinSkill) 
  1858.             return ;
  1859.         pOrdinSkill->Cast(nIdx, MapX, MapY);
  1860. }
  1861. }
  1862. void KProtocolProcess::s2cShowMsg(BYTE *pMsg)
  1863. {
  1864. if (!pMsg)
  1865. return;
  1866. SHOW_MSG_SYNC *pShowMsg = (SHOW_MSG_SYNC*)pMsg;
  1867. switch (pShowMsg->m_wMsgID)
  1868. {
  1869. case enumMSG_ID_TEAM_KICK_One:
  1870. {
  1871. char szName[32];
  1872. KSystemMessage sMsg;
  1873. memset(szName, 0, sizeof(szName));
  1874. memcpy(szName, pMsg + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), pShowMsg->m_wLength + 1 + sizeof(LPVOID) - sizeof(SHOW_MSG_SYNC));
  1875. if (strcmp(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, szName) == 0)
  1876. {
  1877. sprintf(sMsg.szMessage, MSG_TEAM_BE_KICKEN);
  1878. sMsg.eType = SMT_TEAM;
  1879. sMsg.byConfirmType = SMCT_CLICK;
  1880. sMsg.byPriority = 1;
  1881. }
  1882. else
  1883. {
  1884. sprintf(sMsg.szMessage, MSG_TEAM_KICK_ONE, szName);
  1885. sMsg.eType = SMT_NORMAL;
  1886. sMsg.byConfirmType = SMCT_NONE;
  1887. sMsg.byPriority = 0;
  1888. }
  1889. sMsg.byParamSize = 0;
  1890. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1891. }
  1892. break;
  1893. case enumMSG_ID_TEAM_DISMISS:
  1894. {
  1895. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  1896. break;
  1897. KSystemMessage sMsg;
  1898. if (Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFigure == TEAM_CAPTAIN)
  1899. {
  1900. sprintf(sMsg.szMessage, MSG_TEAM_DISMISS_CAPTAIN);
  1901. }
  1902. else
  1903. {
  1904. sprintf(sMsg.szMessage, MSG_TEAM_DISMISS_MEMBER, g_Team[0].m_szMemName[0]);
  1905. }
  1906. sMsg.eType = SMT_TEAM;
  1907. sMsg.byConfirmType = SMCT_CLICK;
  1908. sMsg.byPriority = 1;
  1909. sMsg.byParamSize = 0;
  1910. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1911. }
  1912. break;
  1913. case enumMSG_ID_TEAM_LEAVE:
  1914. {
  1915. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  1916. break;
  1917. KSystemMessage sMsg;
  1918. DWORD dwID = *(DWORD*)(&pShowMsg->m_lpBuf);
  1919. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID == dwID)
  1920. {
  1921. sprintf(sMsg.szMessage, MSG_TEAM_LEAVE_SELF_MSG, g_Team[0].m_szMemName[0]);
  1922. }
  1923. else
  1924. {
  1925. sprintf(sMsg.szMessage, MSG_TEAM_LEAVE, "有人");
  1926. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  1927. {
  1928. if ((DWORD)g_Team[0].m_nMember[i] == dwID)
  1929. {
  1930. sprintf(sMsg.szMessage, MSG_TEAM_LEAVE, g_Team[0].m_szMemName[i + 1]);
  1931. break;
  1932. }
  1933. }
  1934. }
  1935. sMsg.eType = SMT_NORMAL;
  1936. sMsg.byConfirmType = SMCT_NONE;
  1937. sMsg.byPriority = 0;
  1938. sMsg.byParamSize = 0;
  1939. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1940. }
  1941. break;
  1942. case enumMSG_ID_TEAM_REFUSE_INVITE:
  1943. {
  1944. char szName[32];
  1945. memset(szName, 0, sizeof(szName));
  1946. memcpy(szName, &pShowMsg->m_lpBuf, pShowMsg->m_wLength + 1 + sizeof(LPVOID) - sizeof(SHOW_MSG_SYNC));
  1947. KSystemMessage sMsg;
  1948. sprintf(sMsg.szMessage, MSG_TEAM_REFUSE_INVITE, szName);
  1949. sMsg.eType = SMT_NORMAL;
  1950. sMsg.byConfirmType = SMCT_NONE;
  1951. sMsg.byPriority = 0;
  1952. sMsg.byParamSize = 0;
  1953. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1954. }
  1955. break;
  1956. case enumMSG_ID_TEAM_SELF_ADD:
  1957. {
  1958. KSystemMessage sMsg;
  1959. sprintf(sMsg.szMessage, MSG_TEAM_SELF_ADD, g_Team[0].m_szMemName[0]);
  1960. sMsg.eType = SMT_TEAM;
  1961. sMsg.byConfirmType = SMCT_UI_TEAM;
  1962. sMsg.byPriority = 3;
  1963. sMsg.byParamSize = 0;
  1964. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1965. }
  1966. break;
  1967. case enumMSG_ID_TEAM_CHANGE_CAPTAIN_FAIL:
  1968. {
  1969. int nMember;
  1970. DWORD dwID = *(DWORD*)(&pShowMsg->m_lpBuf);
  1971. nMember = g_Team[0].FindMemberID(dwID);
  1972. if (nMember < 0)
  1973. break;
  1974. KSystemMessage sMsg;
  1975. sMsg.eType = SMT_NORMAL;
  1976. sMsg.byConfirmType = SMCT_NONE;
  1977. sMsg.byPriority = 0;
  1978. sMsg.byParamSize = 0;
  1979. sprintf(sMsg.szMessage, MSG_TEAM_CHANGE_CAPTAIN_FAIL1);
  1980. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1981. sprintf(sMsg.szMessage, MSG_TEAM_CHANGE_CAPTAIN_FAIL2, g_Team[0].m_szMemName[nMember + 1]);
  1982. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1983. }
  1984. break;
  1985. case enumMSG_ID_TEAM_CHANGE_CAPTAIN_FAIL2:
  1986. {
  1987. int nMember;
  1988. DWORD dwID = *(DWORD*)(&pShowMsg->m_lpBuf);
  1989. nMember = g_Team[0].FindMemberID(dwID);
  1990. if (nMember < 0)
  1991. break;
  1992. KSystemMessage sMsg;
  1993. sMsg.eType = SMT_NORMAL;
  1994. sMsg.byConfirmType = SMCT_NONE;
  1995. sMsg.byPriority = 0;
  1996. sMsg.byParamSize = 0;
  1997. sprintf(sMsg.szMessage, MSG_TEAM_CHANGE_CAPTAIN_FAIL1);
  1998. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1999. sprintf(sMsg.szMessage, MSG_TEAM_CHANGE_CAPTAIN_FAIL3);
  2000. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2001. }
  2002. break;
  2003. case enumMSG_ID_OBJ_CANNOT_PICKUP:
  2004. {
  2005. KSystemMessage sMsg;
  2006. sMsg.eType = SMT_NORMAL;
  2007. sMsg.byConfirmType = SMCT_NONE;
  2008. sMsg.byPriority = 0;
  2009. sMsg.byParamSize = 0;
  2010. strcpy(sMsg.szMessage, MSG_OBJ_CANNOT_PICKUP);
  2011. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2012. }
  2013. break;
  2014. case enumMSG_ID_OBJ_TOO_FAR:
  2015. {
  2016. KSystemMessage sMsg;
  2017. sMsg.eType = SMT_NORMAL;
  2018. sMsg.byConfirmType = SMCT_NONE;
  2019. sMsg.byPriority = 0;
  2020. sMsg.byParamSize = 0;
  2021. strcpy(sMsg.szMessage, MSG_OBJ_TOO_FAR);
  2022. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2023. }
  2024. break;
  2025. case enumMSG_ID_DEC_MONEY:
  2026. {
  2027. KSystemMessage sMsg;
  2028. sMsg.eType = SMT_NORMAL;
  2029. sMsg.byConfirmType = SMCT_NONE;
  2030. sMsg.byPriority = 0;
  2031. sMsg.byParamSize = 0;
  2032. sprintf(sMsg.szMessage, MSG_DEC_MONEY, (int)pShowMsg->m_lpBuf);
  2033. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2034. }
  2035. break;
  2036. case enumMSG_ID_TRADE_SELF_ROOM_FULL:
  2037. {
  2038. KSystemMessage sMsg;
  2039. sprintf(sMsg.szMessage, MSG_TRADE_SELF_ROOM_FULL);
  2040. sMsg.eType = SMT_SYSTEM;
  2041. sMsg.byConfirmType = SMCT_CLICK;
  2042. sMsg.byPriority = 1;
  2043. sMsg.byParamSize = 0;
  2044. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2045. }
  2046. break;
  2047. case enumMSG_ID_TRADE_DEST_ROOM_FULL:
  2048. {
  2049. KSystemMessage sMsg;
  2050. sprintf(sMsg.szMessage, MSG_TRADE_DEST_ROOM_FULL, Player[CLIENT_PLAYER_INDEX].m_cTrade.m_szDestName);
  2051. sMsg.eType = SMT_NORMAL;
  2052. sMsg.byConfirmType = SMCT_NONE;
  2053. sMsg.byPriority = 0;
  2054. sMsg.byParamSize = 0;
  2055. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2056. }
  2057. break;
  2058. case enumMSG_ID_TRADE_REFUSE_APPLY:
  2059. {
  2060. int nIdx = NpcSet.SearchID(*((DWORD*)&pShowMsg->m_lpBuf));
  2061. if (nIdx <= 0)
  2062. return;
  2063. KSystemMessage sMsg;
  2064. sprintf(sMsg.szMessage, MSG_TRADE_REFUSE_APPLY, Npc[nIdx].Name);
  2065. sMsg.eType = SMT_NORMAL;
  2066. sMsg.byConfirmType = SMCT_NONE;
  2067. sMsg.byPriority = 0;
  2068. sMsg.byParamSize = 0;
  2069. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2070. }
  2071. break;
  2072. case enumMSG_ID_TRADE_TASK_ITEM:
  2073. {
  2074. KSystemMessage sMsg;
  2075. sprintf(sMsg.szMessage, MSG_TRADE_TASK_ITEM);
  2076. sMsg.eType = SMT_NORMAL;
  2077. sMsg.byConfirmType = SMCT_NONE;
  2078. sMsg.byPriority = 0;
  2079. sMsg.byParamSize = 0;
  2080. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2081. }
  2082. break;
  2083. case enumMSG_ID_ITEM_DAMAGED:
  2084. {
  2085. int nItemID = (int)pShowMsg->m_lpBuf;
  2086. int nIdx = ItemSet.SearchID(nItemID);
  2087. if (!nIdx)
  2088. break;
  2089. KSystemMessage sMsg;
  2090. sMsg.eType = SMT_NORMAL;
  2091. sMsg.byConfirmType = SMCT_NONE;
  2092. sMsg.byPriority = 1;
  2093. sMsg.byParamSize = 0;
  2094. sprintf(sMsg.szMessage, MSG_ITEM_DAMAGED, Item[nIdx].GetName());
  2095. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2096. }
  2097. break;
  2098. case enumMSG_ID_GET_ITEM:
  2099. {
  2100. DWORD dwID = *(DWORD*)(&pShowMsg->m_lpBuf);
  2101. int nItemIdx = ItemSet.SearchID(dwID);
  2102. if (nItemIdx <= 0 || nItemIdx >= MAX_ITEM)
  2103. break;
  2104. char szName[128];
  2105. KSystemMessage sMsg;
  2106. strcpy(szName, Item[nItemIdx].GetName());
  2107. if (strlen(szName) >= sizeof(sMsg.szMessage) - strlen(MSG_ADD_ITEM))
  2108. break;
  2109. sMsg.eType = SMT_NORMAL;
  2110. sMsg.byConfirmType = SMCT_NONE;
  2111. sMsg.byPriority = 0;
  2112. sMsg.byParamSize = 0;
  2113. sprintf(sMsg.szMessage, MSG_ADD_ITEM, szName);
  2114. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2115. }
  2116. break;
  2117. case enumMSG_ID_MONEY_CANNOT_PICKUP:
  2118. {
  2119. KSystemMessage sMsg;
  2120. sMsg.eType = SMT_NORMAL;
  2121. sMsg.byConfirmType = SMCT_NONE;
  2122. sMsg.byPriority = 0;
  2123. sMsg.byParamSize = 0;
  2124. strcpy(sMsg.szMessage, MSG_MONEY_CANNOT_PICKUP);
  2125. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2126. }
  2127. break;
  2128. case enumMSG_ID_CANNOT_ADD_TEAM:
  2129. {
  2130. KSystemMessage sMsg;
  2131. sMsg.eType = SMT_NORMAL;
  2132. sMsg.byConfirmType = SMCT_NONE;
  2133. sMsg.byPriority = 0;
  2134. sMsg.byParamSize = 0;
  2135. sprintf(sMsg.szMessage, MSG_TEAM_CANNOT_CREATE);
  2136. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2137. }
  2138. break;
  2139. case enumMSG_ID_TARGET_CANNOT_ADD_TEAM:
  2140. {
  2141. KSystemMessage sMsg;
  2142. sMsg.eType = SMT_NORMAL;
  2143. sMsg.byConfirmType = SMCT_NONE;
  2144. sMsg.byPriority = 0;
  2145. sMsg.byParamSize = 0;
  2146. sprintf(sMsg.szMessage, MSG_TEAM_TARGET_CANNOT_ADD_TEAM);
  2147. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2148. }
  2149. break;
  2150. case enumMSG_ID_PK_ERROR_1:
  2151. {
  2152. KSystemMessage sMsg;
  2153. sMsg.eType = SMT_NORMAL;
  2154. sMsg.byConfirmType = SMCT_NONE;
  2155. sMsg.byPriority = 0;
  2156. sMsg.byParamSize = 0;
  2157. sprintf(sMsg.szMessage, MSG_PK_ERROR_1);
  2158. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2159. }
  2160. break;
  2161. case enumMSG_ID_PK_ERROR_2:
  2162. {
  2163. KSystemMessage sMsg;
  2164. sMsg.eType = SMT_NORMAL;
  2165. sMsg.byConfirmType = SMCT_NONE;
  2166. sMsg.byPriority = 0;
  2167. sMsg.byParamSize = 0;
  2168. sprintf(sMsg.szMessage, MSG_PK_ERROR_2);
  2169. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2170. }
  2171. break;
  2172. case enumMSG_ID_PK_ERROR_3:
  2173. {
  2174. KSystemMessage sMsg;
  2175. sMsg.eType = SMT_NORMAL;
  2176. sMsg.byConfirmType = SMCT_NONE;
  2177. sMsg.byPriority = 0;
  2178. sMsg.byParamSize = 0;
  2179. sprintf(sMsg.szMessage, MSG_PK_ERROR_3);
  2180. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2181. }
  2182. break;
  2183. case enumMSG_ID_PK_ERROR_4:
  2184. {
  2185. KSystemMessage sMsg;
  2186. sMsg.eType = SMT_NORMAL;
  2187. sMsg.byConfirmType = SMCT_NONE;
  2188. sMsg.byPriority = 0;
  2189. sMsg.byParamSize = 0;
  2190. sprintf(sMsg.szMessage, MSG_PK_ERROR_4);
  2191. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2192. }
  2193. break;
  2194. case enumMSG_ID_PK_ERROR_5:
  2195. {
  2196. KSystemMessage sMsg;
  2197. sMsg.eType = SMT_NORMAL;
  2198. sMsg.byConfirmType = SMCT_NONE;
  2199. sMsg.byPriority = 0;
  2200. sMsg.byParamSize = 0;
  2201. sprintf(sMsg.szMessage, MSG_PK_ERROR_5);
  2202. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2203. }
  2204. break;
  2205. case enumMSG_ID_PK_ERROR_6:
  2206. {
  2207. KSystemMessage sMsg;
  2208. sMsg.eType = SMT_NORMAL;
  2209. sMsg.byConfirmType = SMCT_NONE;
  2210. sMsg.byPriority = 0;
  2211. sMsg.byParamSize = 0;
  2212. sprintf(sMsg.szMessage, MSG_PK_ERROR_6);
  2213. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2214. }
  2215. break;
  2216. case enumMSG_ID_PK_ERROR_7:
  2217. {
  2218. KSystemMessage sMsg;
  2219. sMsg.eType = SMT_NORMAL;
  2220. sMsg.byConfirmType = SMCT_NONE;
  2221. sMsg.byPriority = 0;
  2222. sMsg.byParamSize = 0;
  2223. sprintf(sMsg.szMessage, MSG_PK_ERROR_7);
  2224. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2225. }
  2226. break;
  2227. case enumMSG_ID_DEATH_LOSE_ITEM:
  2228. {
  2229. char szName[32];
  2230. memset(szName, 0, sizeof(szName));
  2231. memcpy(szName, &pShowMsg->m_lpBuf, pShowMsg->m_wLength + 1 + sizeof(LPVOID) - sizeof(SHOW_MSG_SYNC));
  2232. KSystemMessage sMsg;
  2233. sMsg.eType = SMT_NORMAL;
  2234. sMsg.byConfirmType = SMCT_NONE;
  2235. sMsg.byPriority = 0;
  2236. sMsg.byParamSize = 0;
  2237. sprintf(sMsg.szMessage, MSG_DEATH_LOSE_ITEM, szName);
  2238. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2239. }
  2240. break;
  2241. case enumMSG_ID_TONG_REFUSE_ADD:
  2242. {
  2243. char szName[32];
  2244. memset(szName, 0, sizeof(szName));
  2245. memcpy(szName, pMsg + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), pShowMsg->m_wLength + 1 + sizeof(LPVOID) - sizeof(SHOW_MSG_SYNC));
  2246. KSystemMessage sMsg;
  2247. sMsg.eType = SMT_NORMAL;
  2248. sMsg.byConfirmType = SMCT_NONE;
  2249. sMsg.byPriority = 0;
  2250. sMsg.byParamSize = 0;
  2251. sprintf(sMsg.szMessage, MSG_TONG_REFUSE_ADD, szName);
  2252. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2253. }
  2254. break;
  2255. case enumMSG_ID_TONG_BE_KICK:
  2256. {
  2257. KSystemMessage sMsg;
  2258. sMsg.eType = SMT_NORMAL;
  2259. sMsg.byConfirmType = SMCT_NONE;
  2260. sMsg.byPriority = 0;
  2261. sMsg.byParamSize = 0;
  2262. sprintf(sMsg.szMessage, MSG_TONG_BE_KICKED);
  2263. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2264. KUiGameObjectWithName sUi;
  2265. strcpy(sUi.szName, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  2266. sUi.nData = TONG_ACTION_DISMISS;
  2267. sUi.nParam = 0;
  2268. sUi.uParam = 0;
  2269. sUi.szString[0] = 0;
  2270. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, 1);
  2271. }
  2272. break;
  2273. case enumMSG_ID_TONG_LEAVE_SUCCESS:
  2274. {
  2275. KSystemMessage sMsg;
  2276. sMsg.eType = SMT_NORMAL;
  2277. sMsg.byConfirmType = SMCT_NONE;
  2278. sMsg.byPriority = 0;
  2279. sMsg.byParamSize = 0;
  2280. sprintf(sMsg.szMessage, MSG_TONG_LEAVE_SUCCESS);
  2281. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2282. }
  2283. break;
  2284. case enumMSG_ID_TONG_LEAVE_FAIL:
  2285. {
  2286. KSystemMessage sMsg;
  2287. sMsg.eType = SMT_NORMAL;
  2288. sMsg.byConfirmType = SMCT_NONE;
  2289. sMsg.byPriority = 0;
  2290. sMsg.byParamSize = 0;
  2291. sprintf(sMsg.szMessage, MSG_TONG_LEAVE_FAIL);
  2292. // CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2293. }
  2294. break;
  2295. case enumMSG_ID_TONG_CHANGE_AS_MASTER:
  2296. {
  2297. KSystemMessage sMsg;
  2298. sMsg.eType = SMT_NORMAL;
  2299. sMsg.byConfirmType = SMCT_NONE;
  2300. sMsg.byPriority = 0;
  2301. sMsg.byParamSize = 0;
  2302. sprintf(sMsg.szMessage, MSG_TONG_CHANGE_AS_MASTER);
  2303. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2304. KUiGameObjectWithName sUi;
  2305. strcpy(sUi.szName, Player[CLIENT_PLAYER_INDEX].m_cTong.m_szMasterName);
  2306. sUi.nData = TONG_ACTION_DEMISE;
  2307. sUi.nParam = 0;
  2308. sUi.uParam = 0;
  2309. sUi.szString[0] = 0;
  2310. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, 1);
  2311. }
  2312. break;
  2313. case enumMSG_ID_TONG_CHANGE_AS_MEMBER:
  2314. {
  2315. KSystemMessage sMsg;
  2316. sMsg.eType = SMT_NORMAL;
  2317. sMsg.byConfirmType = SMCT_NONE;
  2318. sMsg.byPriority = 0;
  2319. sMsg.byParamSize = 0;
  2320. sprintf(sMsg.szMessage, MSG_TONG_CHANGE_AS_MEMBER);
  2321. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2322. KUiGameObjectWithName sUi;
  2323. strcpy(sUi.szName, Player[CLIENT_PLAYER_INDEX].m_cTong.m_szMasterName);
  2324. sUi.nData = TONG_ACTION_DEMISE;
  2325. sUi.nParam = 0;
  2326. sUi.uParam = 0;
  2327. sUi.szString[0] = 0;
  2328. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, 1);
  2329. }
  2330. break;
  2331. default:
  2332. break;
  2333. }
  2334. }
  2335. void KProtocolProcess::SyncStateEffect(BYTE* pMsg)
  2336. {
  2337. STATE_EFFECT_SYNC* pSync = (STATE_EFFECT_SYNC *)pMsg;
  2338. int nDataNum = MAX_SKILL_STATE - (sizeof(STATE_EFFECT_SYNC) - pSync->m_wLength) / sizeof(KMagicAttrib);
  2339. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].SetStateSkillEffect(Player[CLIENT_PLAYER_INDEX].m_nIndex, pSync->m_dwSkillID, pSync->m_nLevel, pSync->m_MagicAttrib, nDataNum, pSync->m_nTime);
  2340. }
  2341. void KProtocolProcess::s2cTradeApplyStart(BYTE* pMsg)
  2342. {
  2343. Player[CLIENT_PLAYER_INDEX].s2cTradeApplyStart(pMsg);
  2344. }
  2345. void KProtocolProcess::s2cItemAutoMove(BYTE* pMsg)
  2346. {
  2347. ITEM_AUTO_MOVE_SYNC *pSync = (ITEM_AUTO_MOVE_SYNC*)pMsg;
  2348. ItemPos sSrc, sDest;
  2349. sSrc.nPlace = pSync->m_btSrcPos;
  2350. sSrc.nX = pSync->m_btSrcX;
  2351. sSrc.nY = pSync->m_btSrcY;
  2352. sDest.nPlace = pSync->m_btDestPos;
  2353. sDest.nX = pSync->m_btDestX;
  2354. sDest.nY = pSync->m_btDestY;
  2355. Player[CLIENT_PLAYER_INDEX].m_ItemList.AutoMoveItem(sSrc, sDest);
  2356. }
  2357. void KProtocolProcess::FinishedItemExchange(BYTE* pMsg)
  2358. {
  2359. Player[CLIENT_PLAYER_INDEX].m_ItemList.UnlockOperation();
  2360. }
  2361. extern IClientCallback* l_pDataChangedNotifyFunc;
  2362. void KProtocolProcess::s2cExtend(BYTE* pMsg)
  2363. {
  2364. EXTEND_HEADER* pHeader = (EXTEND_HEADER*)(pMsg + sizeof(tagExtendProtoHeader));
  2365. if (pHeader->ProtocolFamily == pf_playercommunity)
  2366. {
  2367. if (pHeader->ProtocolID == playercomm_s2c_notifychannelid)
  2368. {
  2369. PLAYERCOMM_NOTIFYCHANNELID* pNChann = (PLAYERCOMM_NOTIFYCHANNELID*)pHeader;
  2370. l_pDataChangedNotifyFunc->NotifyChannelID(pNChann->channel, pNChann->channelid, pNChann->cost);
  2371. }
  2372. }
  2373. }
  2374. void KProtocolProcess::s2cExtendChat(BYTE* pMsg)
  2375. {
  2376. tagExtendProtoHeader* pExHdr = (tagExtendProtoHeader*)pMsg;
  2377. void* pExPckg = pExHdr + 1;
  2378. BYTE protocol = *(BYTE*)(pExPckg);
  2379. if (protocol == chat_someonechat)
  2380. {
  2381. CHAT_SOMEONECHAT_SYNC* pCscSync = (CHAT_SOMEONECHAT_SYNC*)pExPckg;
  2382. l_pDataChangedNotifyFunc->MSNMessageArrival(
  2383. pCscSync->someone, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name,
  2384. (const char*)(pCscSync + 1), pCscSync->sentlen, true);
  2385. }
  2386. else if (protocol == chat_channelchat)
  2387. {
  2388. CHAT_CHANNELCHAT_SYNC* pCccSync = (CHAT_CHANNELCHAT_SYNC*)pExPckg;
  2389. l_pDataChangedNotifyFunc->ChannelMessageArrival(
  2390. pCccSync->channelid, pCccSync->someone,
  2391. (const char*)(pCccSync + 1), pCccSync->sentlen, true);
  2392. }
  2393. else if (protocol == chat_feedback)
  2394. {
  2395. ////X
  2396. CHAT_FEEDBACK* pCfb = (CHAT_FEEDBACK*)pExPckg;
  2397. DWORD* pChannelid = (DWORD*)(pCfb + 1);
  2398. if (*pChannelid == -1)
  2399. {//someone
  2400. char* pDstName = (char*)(pChannelid + 1);
  2401. BYTE* pSentlen = (BYTE*)(pDstName + _NAME_LEN);
  2402. void* pSent = pSentlen + 1;
  2403. l_pDataChangedNotifyFunc->MSNMessageArrival(
  2404. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, pDstName,
  2405. (const char*)pSent, *pSentlen, pCfb->code != codeFail);
  2406. }
  2407. else
  2408. {//channel
  2409. BYTE* pSentlen = (BYTE*)(pChannelid + 1);
  2410. void* pSent = pSentlen + 1;
  2411. l_pDataChangedNotifyFunc->ChannelMessageArrival(
  2412. *pChannelid, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name,
  2413. (const char*)pSent, *pSentlen, pCfb->code != codeFail);
  2414. }
  2415. ////X
  2416. }
  2417. }
  2418. static BOOL sParseUGName(const std::string& name, std::string* pUnit, std::string* pGroup)
  2419. {
  2420. static const char char_split = 'n';
  2421. size_t pos = name.find(char_split);
  2422. if (pos == name.npos)
  2423. {
  2424. if (pUnit)
  2425. pUnit->resize(0);
  2426. if (pGroup)
  2427. pGroup->assign(name);
  2428. }
  2429. else
  2430. {
  2431. std::string::const_iterator itSplit = name.begin() + pos;
  2432. if (pUnit)
  2433. pUnit->assign(name.begin(), itSplit);
  2434. if (pGroup)
  2435. pGroup->assign(itSplit + 1, name.end());
  2436. }
  2437. return TRUE;
  2438. }
  2439. void KProtocolProcess::s2cExtendFriend(BYTE* pMsg)
  2440. {
  2441. tagExtendProtoHeader* pExHdr = (tagExtendProtoHeader*)pMsg;
  2442. void* pExPckg = pExHdr + 1;
  2443. EXTEND_HEADER* pHeader = (EXTEND_HEADER*)(pExPckg);
  2444. if (pHeader->ProtocolFamily == pf_tong)
  2445. {
  2446. _ASSERT(FALSE);
  2447. //tong message
  2448. //...
  2449. }
  2450. else if (pHeader->ProtocolFamily == pf_friend)
  2451. {
  2452. if (pHeader->ProtocolID == friend_c2c_askaddfriend)
  2453. {
  2454. ASK_ADDFRIEND_SYNC* pAafSync = (ASK_ADDFRIEND_SYNC*)pHeader;
  2455. l_pDataChangedNotifyFunc->FriendInvite(pAafSync->srcrole);
  2456. }
  2457. else if (pHeader->ProtocolID == friend_c2c_repaddfriend)
  2458. {
  2459. REP_ADDFRIEND_SYNC* pRafSync = (REP_ADDFRIEND_SYNC*)pHeader;
  2460. l_pDataChangedNotifyFunc->AddFriend(pRafSync->srcrole, pRafSync->answer);
  2461. }
  2462. else if (pHeader->ProtocolID == friend_s2c_repsyncfriendlist)
  2463. {
  2464. REP_SYNCFRIENDLIST* pRsfl = (REP_SYNCFRIENDLIST*)pHeader;
  2465. char* pGroupTag = (char*)(pRsfl + 1);
  2466. if (*pGroupTag != specGroup)
  2467. goto on_error;
  2468. {{
  2469. char* pGroup = (char*)(pGroupTag + 1);
  2470. on_newgroup:
  2471. std::string theUnit, theGroup;
  2472. sParseUGName(std::string(pGroup), &theUnit, &theGroup);
  2473. for (char* pRoleTag = pGroup + strlen(pGroup) + 1; ; )
  2474. {
  2475. if (*pRoleTag == specOver)
  2476. goto on_over;
  2477. else if (*pRoleTag == specGroup)
  2478. {
  2479. pGroup = pRoleTag + 1;
  2480. goto on_newgroup;
  2481. }
  2482. else if (*pRoleTag == specRole)
  2483. {
  2484. char* pState = pRoleTag + 1;
  2485. char* pRole = pState + 1;
  2486. l_pDataChangedNotifyFunc->FriendInfo(pRole, (char*)theUnit.c_str(), (char*)theGroup.c_str(), (BYTE)*pState);
  2487. pRoleTag = pRole + strlen(pRole) + 1;
  2488. continue;
  2489. }
  2490. else
  2491. goto on_error;
  2492. }
  2493. }}
  2494. on_error:
  2495. _ASSERT(FALSE);
  2496. on_over:
  2497. 0;
  2498. }
  2499. else if (pHeader->ProtocolID == friend_s2c_friendstate)
  2500. {
  2501. FRIEND_STATE* pFs = (FRIEND_STATE*)pHeader;
  2502. for (char* pRole = (char*)(pFs + 1); *pRole; pRole += strlen(pRole) + 1)
  2503. l_pDataChangedNotifyFunc->FriendStatus(pRole, pFs->state);
  2504. }
  2505. else if (pHeader->ProtocolID == friend_s2c_syncassociate)
  2506. {
  2507. FRIEND_SYNCASSOCIATE* pFsa = (FRIEND_SYNCASSOCIATE*)pHeader;
  2508. char* szGroup = (char*)(pFsa + 1);
  2509. std::string group(szGroup);
  2510. std::string theUnit, theGroup;
  2511. sParseUGName(group, &theUnit, &theGroup);
  2512. _ASSERT(theGroup.empty());
  2513. for (char* szRole = szGroup + group.size() + 1; *szRole; szRole += strlen(szRole) + 1)
  2514. l_pDataChangedNotifyFunc->AddPeople((char*)theUnit.c_str(), szRole);
  2515. }
  2516. }
  2517. }
  2518. void KProtocolProcess::s2cExtendTong(BYTE* pMsg)
  2519. {
  2520. S2C_TONG_HEAD *pHead = (S2C_TONG_HEAD*)pMsg;
  2521. switch (pHead->m_btMsgId)
  2522. {
  2523. case enumTONG_SYNC_ID_CREATE_FAIL:
  2524. {
  2525. TONG_CREATE_FAIL_SYNC *pFail = (TONG_CREATE_FAIL_SYNC*)pMsg;
  2526. KSystemMessage sMsg;
  2527. sMsg.eType = SMT_NORMAL;
  2528. sMsg.byConfirmType = SMCT_NONE;
  2529. sMsg.byPriority = 0;
  2530. sMsg.byParamSize = 0;
  2531. sprintf(sMsg.szMessage, "帮会创建失败!");
  2532. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2533. switch (pFail->m_btFailId)
  2534. {
  2535. case enumTONG_CREATE_ERROR_ID1: // Player[m_nPlayerIndex].m_nIndex <= 0
  2536. break;
  2537. case enumTONG_CREATE_ERROR_ID2: // 交易过程中
  2538. break;
  2539. case enumTONG_CREATE_ERROR_ID3: // 帮会名问题
  2540. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR09);
  2541. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2542. break;
  2543. case enumTONG_CREATE_ERROR_ID4: // 帮会阵营问题
  2544. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR02);
  2545. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2546. break;
  2547. case enumTONG_CREATE_ERROR_ID5: // 已经是帮会成员
  2548. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR03);
  2549. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2550. break;
  2551. case enumTONG_CREATE_ERROR_ID6: // 自己的阵营问题
  2552. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR04);
  2553. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2554. break;
  2555. case enumTONG_CREATE_ERROR_ID7: // 等级问题
  2556. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR05);
  2557. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2558. break;
  2559. case enumTONG_CREATE_ERROR_ID8: // 钱问题
  2560. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR10);
  2561. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2562. break;
  2563. case enumTONG_CREATE_ERROR_ID9: // 组队不能建帮会
  2564. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR08);
  2565. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2566. break;
  2567. case enumTONG_CREATE_ERROR_ID10: // 帮会模块出错
  2568. break;
  2569. case enumTONG_CREATE_ERROR_ID11: // 名字字符串出错
  2570. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR11);
  2571. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2572. break;
  2573. case enumTONG_CREATE_ERROR_ID12: // 名字字符串过长
  2574. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR11);
  2575. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2576. break;
  2577. case enumTONG_CREATE_ERROR_ID13: // 帮会同名错误
  2578. sprintf(sMsg.szMessage, MSG_TONG_CREATE_ERROR11);
  2579. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2580. break;
  2581. case enumTONG_CREATE_ERROR_ID14: // 帮会产生失败
  2582. break;
  2583. }
  2584. }
  2585. break;
  2586. case enumTONG_SYNC_ID_TRANSFER_ADD_APPLY:
  2587. {
  2588. TONG_APPLY_ADD_SYNC *pApply = (TONG_APPLY_ADD_SYNC*)pMsg;
  2589. char szName[32];
  2590. DWORD dwNameID;
  2591. int nPlayerIdx;
  2592. memset(szName, 0, sizeof(szName));
  2593. memcpy(szName, pApply->m_szName, pApply->m_wLength + 1 + sizeof(pApply->m_szName) - sizeof(TONG_APPLY_ADD_SYNC));
  2594. dwNameID = g_FileName2Id(szName);
  2595. nPlayerIdx = pApply->m_nPlayerIdx;
  2596. // 给界面发消息,收到申请,是否同意
  2597. KSystemMessage sMsg;
  2598. sprintf(sMsg.szMessage, "%s申请加入帮会!", szName);
  2599. sMsg.eType = SMT_CLIQUE;
  2600. sMsg.byConfirmType = SMCT_UI_TONG_JOIN_APPLY;
  2601. sMsg.byPriority = 3;
  2602. sMsg.byParamSize = sizeof(KUiPlayerItem);
  2603. KUiPlayerItem player;
  2604. strcpy(player.Name, szName);
  2605. player.nIndex = pApply->m_nPlayerIdx;
  2606. player.uId = 0;
  2607. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, (int)&player);
  2608. }
  2609. break;
  2610. case enumTONG_SYNC_ID_ADD:
  2611. {
  2612. TONG_Add_SYNC *pAdd = (TONG_Add_SYNC*)pMsg;
  2613. char szName[32], szTitle[32], szMaster[32];
  2614. memcpy(szName, pAdd->m_szTongName,sizeof(szName));
  2615. memcpy(szTitle, pAdd->m_szTitle, sizeof(szTitle));
  2616. memcpy(szMaster, pAdd->m_szMaster, sizeof(szMaster));
  2617. Player[CLIENT_PLAYER_INDEX].m_cTong.AddTong(pAdd->m_btCamp, szName, szTitle, szMaster);
  2618. // 通知界面更新数据
  2619. KUiGameObjectWithName sUi;
  2620. memset(&sUi, 0, sizeof(sUi));
  2621. strcpy(sUi.szName, szName);
  2622. sUi.nData = TONG_ACTION_APPLY;
  2623. strcpy(sUi.szString, szTitle);
  2624. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, 1);
  2625. /*------------------------------*/
  2626. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  2627. }
  2628. break;
  2629. case enumTONG_SYNC_ID_HEAD_INFO:
  2630. {
  2631. TONG_HEAD_INFO_SYNC *pInfo = (TONG_HEAD_INFO_SYNC*)pMsg;
  2632. // 通知界面得到某帮会信息
  2633. int nIdx = NpcSet.SearchID(pInfo->m_dwNpcID);
  2634. if (nIdx <= 0)
  2635. break;
  2636. KUiPlayerRelationWithOther sUi;
  2637. sUi.nIndex = nIdx;
  2638. sUi.uId = Npc[nIdx].m_dwID;
  2639. if (nIdx == Player[CLIENT_PLAYER_INDEX].m_nIndex)
  2640. sUi.nRelation = Player[CLIENT_PLAYER_INDEX].m_cTong.GetFigure();
  2641. else
  2642. sUi.nRelation = -1;
  2643. sUi.nData = 0;
  2644. sUi.nParam = 0;
  2645. strcpy(sUi.Name, Npc[nIdx].Name);
  2646. KTongInfo sInfo;
  2647. memset(&sInfo, 0, sizeof(sInfo));
  2648. sInfo.nFaction = pInfo->m_btCamp;
  2649. sInfo.nMemberCount = (int)pInfo->m_dwMemberNum;
  2650. sInfo.nManagerCount = (int)pInfo->m_btManagerNum;
  2651. sInfo.nDirectorCount = (int)pInfo->m_btDirectorNum;
  2652. sInfo.nMoney = pInfo->m_dwMoney;
  2653. strcpy(sInfo.szMasterName, pInfo->m_sMember[0].m_szName);
  2654. strcpy(sInfo.szName, pInfo->m_szTongName);
  2655. CoreDataChanged(GDCNI_TONG_INFO, (unsigned int)&sUi, (unsigned int)&sInfo);
  2656. KUiGameObjectWithName sObj;
  2657. strcpy(sObj.szName, pInfo->m_szTongName);
  2658. sObj.nData = enumTONG_FIGURE_DIRECTOR;
  2659. sObj.nParam = 0;
  2660. sObj.uParam = defTONG_MAX_DIRECTOR;
  2661. sObj.szString[0] = 0;
  2662. KTongMemberItem sItem[defTONG_MAX_DIRECTOR];
  2663. memset(sItem, 0, sizeof(sItem));
  2664. for (int i = 0; i < pInfo->m_btDirectorNum; i++)
  2665. {
  2666. sItem[i].nData = enumTONG_FIGURE_DIRECTOR;
  2667. strcpy(sItem[i].Name, pInfo->m_sMember[i + 1].m_szName);
  2668. strcpy(sItem[i].szAgname, pInfo->m_sMember[i + 1].m_szTitle);
  2669. }
  2670. CoreDataChanged(GDCNI_TONG_MEMBER_LIST, (unsigned int)&sObj, (unsigned int)sItem);
  2671. }
  2672. break;
  2673. case enumTONG_SYNC_ID_SELF_INFO:
  2674. {
  2675. TONG_SELF_INFO_SYNC *pInfo = (TONG_SELF_INFO_SYNC*)pMsg;
  2676. Player[CLIENT_PLAYER_INDEX].m_cTong.SetSelfInfo(pInfo);
  2677. // 通知界面更新数据
  2678. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  2679. }
  2680. break;
  2681. case enumTONG_SYNC_ID_MANAGER_INFO:
  2682. {
  2683. TONG_MANAGER_INFO_SYNC *pInfo = (TONG_MANAGER_INFO_SYNC*)pMsg;
  2684. // 通知界面得到某帮会队长信息
  2685. KUiGameObjectWithName sObj;
  2686. strcpy(sObj.szName, pInfo->m_szTongName);
  2687. sObj.nData = enumTONG_FIGURE_MANAGER;
  2688. sObj.nParam = pInfo->m_btStateNo;
  2689. sObj.uParam = pInfo->m_btCurNum;
  2690. sObj.szString[0] = 0;
  2691. KTongMemberItem sItem[defTONG_ONE_PAGE_MAX_NUM];
  2692. memset(sItem, 0, sizeof(sItem));
  2693. for (int i = 0; i < pInfo->m_btCurNum; i++)
  2694. {
  2695. sItem[i].nData = enumTONG_FIGURE_MANAGER;
  2696. strcpy(sItem[i].Name, pInfo->m_sMember[i].m_szName);
  2697. strcpy(sItem[i].szAgname, pInfo->m_sMember[i].m_szTitle);
  2698. }
  2699. CoreDataChanged(GDCNI_TONG_MEMBER_LIST, (unsigned int)&sObj, (unsigned int)sItem);
  2700. }
  2701. break;
  2702. case enumTONG_SYNC_ID_MEMBER_INFO:
  2703. {
  2704. TONG_MEMBER_INFO_SYNC *pInfo = (TONG_MEMBER_INFO_SYNC*)pMsg;
  2705. // 通知界面得到某帮会帮众信息
  2706. KUiGameObjectWithName sObj;
  2707. strcpy(sObj.szName, pInfo->m_szTongName);
  2708. sObj.nData = enumTONG_FIGURE_MEMBER;
  2709. sObj.nParam = pInfo->m_btStateNo;
  2710. sObj.uParam = pInfo->m_btCurNum;
  2711. sObj.szString[0] = 0;
  2712. KTongMemberItem sItem[defTONG_ONE_PAGE_MAX_NUM];
  2713. memset(sItem, 0, sizeof(sItem));
  2714. for (int i = 0; i < pInfo->m_btCurNum; i++)
  2715. {
  2716. sItem[i].nData = enumTONG_FIGURE_MEMBER;
  2717. strcpy(sItem[i].Name, pInfo->m_sMember[i].m_szName);
  2718. strcpy(sItem[i].szAgname, pInfo->m_szTitle);
  2719. }
  2720. CoreDataChanged(GDCNI_TONG_MEMBER_LIST, (unsigned int)&sObj, (unsigned int)sItem);
  2721. }
  2722. break;
  2723. case enumTONG_SYNC_ID_INSTATE:
  2724. {
  2725. TONG_INSTATE_SYNC *pInstate = (TONG_INSTATE_SYNC*)pMsg;
  2726. // 通知界面任命是否成功
  2727. KUiGameObjectWithName sUi;
  2728. strcpy(sUi.szName, pInstate->m_szName);
  2729. sUi.nData = TONG_ACTION_ASSIGN;
  2730. sUi.nParam = pInstate->m_btNewFigure;
  2731. sUi.uParam = pInstate->m_btOldFigure;
  2732. strcpy(sUi.szString, pInstate->m_szTitle);
  2733. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, pInstate->m_btSuccessFlag);
  2734. }
  2735. break;
  2736. case enumTONG_SYNC_ID_KICK:
  2737. {
  2738. TONG_KICK_SYNC *pKick = (TONG_KICK_SYNC*)pMsg;
  2739. // 通知界面踢人是否成功
  2740. KUiGameObjectWithName sUi;
  2741. strcpy(sUi.szName, pKick->m_szName);
  2742. sUi.nData = TONG_ACTION_DISMISS;
  2743. sUi.nParam = pKick->m_btFigure;
  2744. sUi.uParam = pKick->m_btPos;
  2745. sUi.szString[0] = 0;
  2746. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, pKick->m_btSuccessFlag);
  2747. }
  2748. break;
  2749. case enumTONG_SYNC_ID_CHANGE_MASTER_FAIL:
  2750. {
  2751. TONG_CHANGE_MASTER_FAIL_SYNC *pFail = (TONG_CHANGE_MASTER_FAIL_SYNC*)pMsg;
  2752. switch (pFail->m_btFailID)
  2753. {
  2754. case 0: // 对方不在线
  2755. {
  2756. KSystemMessage sMsg;
  2757. sMsg.eType = SMT_NORMAL;
  2758. sMsg.byConfirmType = SMCT_NONE;
  2759. sMsg.byPriority = 0;
  2760. sMsg.byParamSize = 0;
  2761. sprintf(sMsg.szMessage, "传位失败,对方不在线!");
  2762. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2763. }
  2764. break;
  2765. case 1: // 对方能力不够!
  2766. {
  2767. KSystemMessage sMsg;
  2768. sMsg.eType = SMT_NORMAL;
  2769. sMsg.byConfirmType = SMCT_NONE;
  2770. sMsg.byPriority = 0;
  2771. sMsg.byParamSize = 0;
  2772. sprintf(sMsg.szMessage, "传位失败,对方能力不够!");
  2773. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2774. }
  2775. break;
  2776. case 2: // 名字不对!
  2777. {
  2778. KSystemMessage sMsg;
  2779. sMsg.eType = SMT_NORMAL;
  2780. sMsg.byConfirmType = SMCT_NONE;
  2781. sMsg.byPriority = 0;
  2782. sMsg.byParamSize = 0;
  2783. sprintf(sMsg.szMessage, "传位失败,本帮中无此人!");
  2784. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2785. }
  2786. break;
  2787. default:
  2788. break;
  2789. }
  2790. }
  2791. break;
  2792. default:
  2793. break;
  2794. }
  2795. }
  2796. void KProtocolProcess::s2cChangeWeather(BYTE* pMsg)
  2797. {
  2798. g_ScenePlace.ChangeWeather(((SYNC_WEATHER*)pMsg)->WeatherID);
  2799. }
  2800. void KProtocolProcess::s2cPKSyncNormalFlag(BYTE* pMsg)
  2801. {
  2802. PK_NORMAL_FLAG_SYNC *pFlag = (PK_NORMAL_FLAG_SYNC*)pMsg;
  2803. Player[CLIENT_PLAYER_INDEX].m_cPK.SetNormalPKState(pFlag->m_btFlag);
  2804. }
  2805. void KProtocolProcess::s2cPKSyncEnmityState(BYTE* pMsg)
  2806. {
  2807. PK_ENMITY_STATE_SYNC *pState = (PK_ENMITY_STATE_SYNC*)pMsg;
  2808. char szName[32];
  2809. memset(szName, 0, sizeof(szName));
  2810. memcpy(szName, pState->m_szName, pState->m_wLength + 1 + sizeof(pState->m_szName) - sizeof(PK_ENMITY_STATE_SYNC));
  2811. Player[CLIENT_PLAYER_INDEX].m_cPK.SetEnmityPKState(pState->m_btState, pState->m_dwNpcID, szName);
  2812. }
  2813. void KProtocolProcess::s2cPKSyncExerciseState(BYTE* pMsg)
  2814. {
  2815. PK_EXERCISE_STATE_SYNC *pState = (PK_EXERCISE_STATE_SYNC*)pMsg;
  2816. char szName[32];
  2817. memset(szName, 0, sizeof(szName));
  2818. memcpy(szName, pState->m_szName, pState->m_wLength + 1 + sizeof(pState->m_szName) - sizeof(PK_EXERCISE_STATE_SYNC));
  2819. Player[CLIENT_PLAYER_INDEX].m_cPK.SetExercisePKState(pState->m_btState, pState->m_dwNpcID, szName);
  2820. }
  2821. void KProtocolProcess::s2cPKValueSync(BYTE* pMsg)
  2822. {
  2823. PK_VALUE_SYNC *pValue = (PK_VALUE_SYNC*)pMsg;
  2824. Player[CLIENT_PLAYER_INDEX].m_cPK.SetPKValue(pValue->m_nPKValue);
  2825. }
  2826. void KProtocolProcess::s2cViewEquip(BYTE* pMsg)
  2827. {
  2828. g_cViewItem.GetData(pMsg);
  2829. }
  2830. void KProtocolProcess::s2cTongCreate(BYTE* pMsg)
  2831. {
  2832. Player[CLIENT_PLAYER_INDEX].m_cTong.Create((TONG_CREATE_SYNC*)pMsg);
  2833. }
  2834. void KProtocolProcess::s2cNpcGoldChange(BYTE* pMsg)
  2835. {
  2836. NPC_GOLD_CHANGE_SYNC *pSync = (NPC_GOLD_CHANGE_SYNC*)pMsg;
  2837. int nIdx = NpcSet.SearchID(pSync->m_dwNpcID);
  2838. if (nIdx && Npc[nIdx].m_Kind == kind_normal)
  2839. {
  2840. Npc[nIdx].m_cGold.SetGoldCurrentType((int)pSync->m_wGoldFlag);
  2841. }
  2842. }
  2843. void KProtocolProcess::ItemChangeDurability(BYTE* pMsg)
  2844. {
  2845. ITEM_DURABILITY_CHANGE *pIDC = (ITEM_DURABILITY_CHANGE *)pMsg;
  2846. int nIdx = ItemSet.SearchID(pIDC->dwItemID);
  2847. if (nIdx)
  2848. {
  2849. Item[nIdx].SetDurability(Item[nIdx].GetDurability() + pIDC->nChange);
  2850. _ASSERT(Item[nIdx].GetDurability() > 0);
  2851. if (Item[nIdx].GetDurability() <= 3)
  2852. {
  2853. KSystemMessage sMsg;
  2854. sMsg.eType = SMT_NORMAL;
  2855. sMsg.byConfirmType = SMCT_NONE;
  2856. sMsg.byPriority = 1;
  2857. sMsg.byParamSize = 0;
  2858. sprintf(sMsg.szMessage, MSG_ITEM_NEARLY_DAMAGED, Item[nIdx].GetName());
  2859. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2860. }
  2861. }
  2862. }
  2863. void KProtocolProcess::LadderList(BYTE* pMsg)
  2864. {
  2865. LADDER_LIST* pList = (LADDER_LIST *)pMsg;
  2866. KRankIndex *pLadderListIndex = NULL;
  2867. if (pList->nCount > 0 && pList->nCount < enumLadderEnd)
  2868. {
  2869. pLadderListIndex = new KRankIndex[pList->nCount];
  2870. }
  2871. if (pLadderListIndex)
  2872. {
  2873. for (int i = 0; i < pList->nCount; i++)
  2874. {
  2875. pLadderListIndex[i].usIndexId = pList->dwLadderID[i];
  2876. pLadderListIndex[i].bValueAppened = true;
  2877. pLadderListIndex[i].bSortFlag = true;
  2878. }
  2879. CoreDataChanged(GDCNII_RANK_INDEX_LIST_ARRIVE, pList->nCount, (int)pLadderListIndex);
  2880. delete [] pLadderListIndex;
  2881. pLadderListIndex = NULL;
  2882. }
  2883. }
  2884. void KProtocolProcess::LadderResult(BYTE* pMsg)
  2885. {
  2886. LADDER_DATA* pLadderData = (LADDER_DATA *)pMsg;
  2887. KRankMessage* pLadderMessage = NULL;
  2888. pLadderMessage = new KRankMessage[10];
  2889. if (pLadderMessage)
  2890. {
  2891. for (int i = 0; i < 10; i++)
  2892. {
  2893. pLadderMessage[i].usMsgLen = strlen(pLadderData->StatData[i].Name);
  2894. strcpy(pLadderMessage[i].szMsg, pLadderData->StatData[i].Name);
  2895. pLadderMessage[i].nValueAppend = pLadderData->StatData[i].nValue;
  2896. pLadderMessage[i].cSortFlag = (char)pLadderData->StatData[i].bySort;
  2897. }
  2898. unsigned int uParam = 10 | (((WORD)pLadderData->dwLadderID) << 16);
  2899. CoreDataChanged(GDCNII_RANK_INFORMATION_ARRIVE, uParam, (int)pLadderMessage);
  2900. delete [] pLadderMessage;
  2901. pLadderMessage = NULL;
  2902. }
  2903. }
  2904. #else
  2905. void KProtocolProcess::RemoveRole(int nIndex, BYTE * pProtocol)
  2906. {
  2907. }
  2908. void KProtocolProcess::NpcRequestCommand(int nIndex, BYTE* pProtocol)
  2909. {
  2910. NPC_REQUEST_COMMAND *pNpcRequestSync = (NPC_REQUEST_COMMAND *)pProtocol;
  2911. NpcSet.SyncNpc(pNpcRequestSync->ID, Player[nIndex].m_nNetConnectIdx);
  2912. }
  2913. //-------------------------------------------------------------------------
  2914. // 功能:客户端向服务器请求更新某个obj数据
  2915. //-------------------------------------------------------------------------
  2916. void KProtocolProcess::ObjRequestCommand(int nIndex, BYTE* pProtocol)
  2917. {
  2918. OBJ_CLIENT_SYNC_ADD *pObjClientSyncAdd = (OBJ_CLIENT_SYNC_ADD*)pProtocol;
  2919. ObjSet.SyncAdd(pObjClientSyncAdd->m_nID, Player[nIndex].m_nNetConnectIdx);
  2920. }
  2921. void KProtocolProcess::NpcWalkCommand(int nIndex, BYTE* pProtocol)
  2922. {
  2923. NPC_WALK_COMMAND* pNetCommand = (NPC_WALK_COMMAND *)pProtocol;
  2924. int ParamX = pNetCommand->nMpsX;
  2925. int ParamY = pNetCommand->nMpsY;
  2926. if (ParamX < 0)
  2927. {
  2928. ParamX = 0;
  2929. }
  2930. if (ParamY < 0)
  2931. {
  2932. ParamY = 0;
  2933. }
  2934. Npc[Player[nIndex].m_nIndex].SendCommand(do_walk, ParamX, ParamY);
  2935. }
  2936. void KProtocolProcess::NpcRunCommand(int nIndex, BYTE* pProtocol)
  2937. {
  2938. NPC_RUN_COMMAND* pNetCommand = (NPC_RUN_COMMAND *)pProtocol;
  2939. int ParamX = pNetCommand->nMpsX;
  2940. int ParamY = pNetCommand->nMpsY;
  2941. if (ParamX < 0)
  2942. {
  2943. ParamX = 0;
  2944. }
  2945. if (ParamY < 0)
  2946. {
  2947. ParamY = 0;
  2948. }
  2949. Npc[Player[nIndex].m_nIndex].SendCommand(do_run, ParamX, ParamY);
  2950. }
  2951. void KProtocolProcess::NpcSkillCommand(int nIndex, BYTE* pProtocol)
  2952. {
  2953. NPC_SKILL_COMMAND* pNetCommand = (NPC_SKILL_COMMAND *)pProtocol;
  2954. int ParamX = pNetCommand->nSkillID;
  2955. int ParamY = pNetCommand->nMpsX;
  2956. int ParamZ = pNetCommand->nMpsY;
  2957. // 参数合法性检查
  2958. if (ParamX <= 0 || ParamX > MAX_SKILL )
  2959. {
  2960. return ;
  2961. }
  2962. if (ParamZ < 0) 
  2963. return;
  2964. if (ParamY < 0)
  2965. {
  2966. if (ParamY != -1) 
  2967. return;
  2968. int nNpcIndex = Player[nIndex].FindAroundNpc((DWORD)ParamZ);
  2969. if (nNpcIndex > 0)
  2970. Npc[Player[nIndex].m_nIndex].SendCommand(do_skill, ParamX, ParamY, nNpcIndex);
  2971. }
  2972. else
  2973. Npc[Player[nIndex].m_nIndex].SendCommand(do_skill, ParamX, ParamY, ParamZ);
  2974. }
  2975. void KProtocolProcess::NpcJumpCommand(int nIndex, BYTE* pProtocol)
  2976. {
  2977. NPC_JUMP_COMMAND* pNetCommand = (NPC_JUMP_COMMAND *)pProtocol;
  2978. int ParamX = pNetCommand->nMpsX;
  2979. int ParamY = pNetCommand->nMpsY;
  2980. Npc[Player[nIndex].m_nIndex].SendCommand(do_jump, ParamX, ParamY);
  2981. }
  2982. void KProtocolProcess::NpcTalkCommand(int nIndex, BYTE* pProtocol)
  2983. {
  2984. }
  2985. void KProtocolProcess::PlayerTalkCommand(int nIndex, BYTE* pProtocol)
  2986. {
  2987. Npc[Player[nIndex].m_nIndex].DoPlayerTalk((char *)pProtocol + 1);
  2988. }
  2989. void KProtocolProcess::PlayerApplyTeamInfo(int nIndex, BYTE* pProtocol)
  2990. {
  2991. Player[nIndex].S2CSendTeamInfo(pProtocol);
  2992. }
  2993. void KProtocolProcess::PlayerApplyCreateTeam(int nIndex, BYTE* pProtocol)
  2994. {
  2995. Player[nIndex].CreateTeam(pProtocol);
  2996. }
  2997. void KProtocolProcess::PlayerApplyTeamOpenClose(int nIndex, BYTE* pProtocol)
  2998. {
  2999. Player[nIndex].SetTeamState(pProtocol);
  3000. }
  3001. void KProtocolProcess::PlayerApplyAddTeam(int nIndex, BYTE* pProtocol)
  3002. {
  3003. Player[nIndex].S2CSendAddTeamInfo(pProtocol);
  3004. }
  3005. void KProtocolProcess::PlayerAcceptTeamMember(int nIndex, BYTE* pProtocol)
  3006. {
  3007. Player[nIndex].AddTeamMember(pProtocol);
  3008. }
  3009. void KProtocolProcess::PlayerApplyLeaveTeam(int nIndex, BYTE* pProtocol)
  3010. {
  3011. Player[nIndex].LeaveTeam(pProtocol);
  3012. }
  3013. void KProtocolProcess::PlayerApplyTeamKickMember(int nIndex, BYTE* pProtocol)
  3014. {
  3015. Player[nIndex].TeamKickOne(pProtocol);
  3016. }
  3017. void KProtocolProcess::PlayerApplyTeamChangeCaptain(int nIndex, BYTE* pProtocol)
  3018. {
  3019. Player[nIndex].TeamChangeCaptain(pProtocol);
  3020. }
  3021. void KProtocolProcess::PlayerApplyTeamDismiss(int nIndex, BYTE* pProtocol)
  3022. {
  3023. Player[nIndex].TeamDismiss(pProtocol);
  3024. }
  3025. void KProtocolProcess::PlayerApplySetPK(int nIndex, BYTE* pProtocol)
  3026. {
  3027. Player[nIndex].SetPK(pProtocol);
  3028. }
  3029. void KProtocolProcess::PlayerApplyFactionData(int nIndex, BYTE* pProtocol)
  3030. {
  3031. Player[nIndex].SendFactionData(pProtocol);
  3032. }
  3033. void KProtocolProcess::PlayerSendChat(int nIndex, BYTE* pProtocol)
  3034. {
  3035. Player[nIndex].ServerSendChat(pProtocol);
  3036. }
  3037. void KProtocolProcess::PlayerAddBaseAttribute(int nIndex, BYTE* pProtocol)
  3038. {
  3039. Player[nIndex].AddBaseAttribute(pProtocol);
  3040. }
  3041. void KProtocolProcess::PlayerApplyAddSkillPoint(int nIndex, BYTE* pProtocol)
  3042. {
  3043. Player[nIndex].AddSkillPoint(pProtocol);
  3044. }
  3045. void KProtocolProcess::PlayerEatItem(int nIndex, BYTE* pProtocol)
  3046. {
  3047. if (Player[nIndex].CheckTrading())
  3048. return;
  3049. Player[nIndex].EatItem(pProtocol);
  3050. }
  3051. void KProtocolProcess::PlayerPickUpItem(int nIndex, BYTE* pProtocol)
  3052. {
  3053. if (Player[nIndex].CheckTrading())
  3054. return;
  3055. Player[nIndex].ServerPickUpItem(pProtocol);
  3056. }
  3057. void KProtocolProcess::PlayerMoveItem(int nIndex, BYTE* pProtocol)
  3058. {
  3059. Player[nIndex].ServerMoveItem(pProtocol);
  3060. }
  3061. void KProtocolProcess::PlayerSellItem(int nIndex, BYTE* pProtocol)
  3062. {
  3063. if (Player[nIndex].CheckTrading())
  3064. return;
  3065. Player[nIndex].SellItem(pProtocol);
  3066. }
  3067. void KProtocolProcess::PlayerBuyItem(int nIndex, BYTE* pProtocol)
  3068. {
  3069. if (Player[nIndex].CheckTrading())
  3070. return;
  3071. Player[nIndex].BuyItem(pProtocol);
  3072. }
  3073. void KProtocolProcess::PlayerDropItem(int nIndex, BYTE* pProtocol)
  3074. {
  3075. if (Player[nIndex].CheckTrading())
  3076. return;
  3077. Player[nIndex].ServerThrowAwayItem(pProtocol);
  3078. }
  3079. void KProtocolProcess::PlayerSelUI(int nIndex, BYTE* pProtocol)
  3080. {
  3081. Player[nIndex].ProcessPlayerSelectFromUI(pProtocol);
  3082. }
  3083. void KProtocolProcess::ChatSetChannel(int nIndex, BYTE* pProtocol)
  3084. {
  3085. Player[nIndex].ChatSetTakeChannel(pProtocol);
  3086. }
  3087. void KProtocolProcess::ChatApplyAddFriend(int nIndex, BYTE* pProtocol)
  3088. {
  3089. Player[nIndex].ChatTransmitApplyAddFriend(pProtocol);
  3090. }
  3091. void KProtocolProcess::ChatAddFriend(int nIndex, BYTE* pProtocol)
  3092. {
  3093. Player[nIndex].ChatAddFriend(pProtocol);
  3094. }
  3095. void KProtocolProcess::ChatRefuseFriend(int nIndex, BYTE* pProtocol)
  3096. {
  3097. Player[nIndex].ChatRefuseFriend(pProtocol);
  3098. }
  3099. void KProtocolProcess::ChatApplyReSendAllFriendName(int nIndex, BYTE* pProtocol)
  3100. {
  3101. Player[nIndex].ChatResendAllFriend(pProtocol);
  3102. }
  3103. void KProtocolProcess::ChatApplySendOneFriendName(int nIndex, BYTE* pProtocol)
  3104. {
  3105. Player[nIndex].ChatSendOneFriendData(pProtocol);
  3106. }
  3107. void KProtocolProcess::ChatDeleteFriend(int nIndex, BYTE* pProtocol)
  3108. {
  3109. Player[nIndex].ChatDeleteFriend(pProtocol);
  3110. }
  3111. void KProtocolProcess::ChatReDeleteFriend(int nIndex, BYTE* pProtocol)
  3112. {
  3113. Player[nIndex].ChatRedeleteFriend(pProtocol);
  3114. }
  3115. void KProtocolProcess::TradeApplyOpen(int nIndex, BYTE* pProtocol)
  3116. {
  3117. Player[nIndex].TradeApplyOpen(pProtocol);
  3118. }
  3119. void KProtocolProcess::TradeApplyClose(int nIndex, BYTE* pProtocol)
  3120. {
  3121. Player[nIndex].TradeApplyClose(pProtocol);
  3122. }
  3123. void KProtocolProcess::TradeApplyStart(int nIndex, BYTE* pProtocol)
  3124. {
  3125. Player[nIndex].TradeApplyStart(pProtocol);
  3126. }
  3127. void KProtocolProcess::TradeMoveMoney(int nIndex, BYTE* pProtocol)
  3128. {
  3129. Player[nIndex].TradeMoveMoney(pProtocol);
  3130. }
  3131. void KProtocolProcess::TradeDecision(int nIndex, BYTE* pProtocol)
  3132. {
  3133. Player[nIndex].TradeDecision(pProtocol);
  3134. }
  3135. void KProtocolProcess::DialogNpc(int nIndex, BYTE * pProtocol)
  3136. {
  3137. Player[nIndex].DialogNpc(pProtocol) ;
  3138. }
  3139. void KProtocolProcess::TeamInviteAdd(int nIndex, BYTE * pProtocol)
  3140. {
  3141. Player[nIndex].m_cTeam.InviteAdd(nIndex, (TEAM_INVITE_ADD_COMMAND*)pProtocol);
  3142. }
  3143. void KProtocolProcess::ChangeAuraSkill(int nIndex, BYTE * pProtocol)
  3144. {
  3145. SKILL_CHANGEAURASKILL_COMMAND * pCommand = (SKILL_CHANGEAURASKILL_COMMAND*) pProtocol;
  3146. Npc[Player[nIndex].m_nIndex].SetAuraSkill(pCommand->m_nAuraSkill);
  3147. }
  3148. void KProtocolProcess::TeamReplyInvite(int nIndex, BYTE * pProtocol)
  3149. {
  3150. TEAM_REPLY_INVITE_COMMAND *pReply = (TEAM_REPLY_INVITE_COMMAND*)pProtocol;
  3151. if (!pProtocol ||
  3152. pReply->m_nIndex <= 0 ||
  3153. pReply->m_nIndex >= MAX_PLAYER ||
  3154. Player[pReply->m_nIndex].m_nIndex <= 0)
  3155. return;
  3156. if (pReply->m_btResult && Player[nIndex].m_cTeam.GetCanTeamFlag() == FALSE)
  3157. {
  3158. SHOW_MSG_SYNC sMsg;
  3159. sMsg.ProtocolType = s2c_msgshow;
  3160. sMsg.m_wMsgID = enumMSG_ID_CANNOT_ADD_TEAM;
  3161. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  3162. g_pServer->PackDataToClient(Player[nIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  3163. return;
  3164. }
  3165. Player[pReply->m_nIndex].m_cTeam.GetInviteReply(pReply->m_nIndex, nIndex, pReply->m_btResult);
  3166. }
  3167. //void KProtocolProcess::ReplyPing(int nIndex, BYTE* pProtocol)
  3168. //{
  3169. // if (nIndex <= 0 || nIndex >= MAX_PLAYER)
  3170. // return;
  3171. //
  3172. // PING_COMMAND PingCmd, *pPingCmd;
  3173. //
  3174. // pPingCmd = (PING_COMMAND *)pProtocol;
  3175. //
  3176. // PingCmd.ProtocolType = s2c_ping;
  3177. // PingCmd.m_dwTime = pPingCmd->m_dwTime;
  3178. // g_pServer->SendData(Player[nIndex].m_nNetConnectIdx, &PingCmd, sizeof(PING_COMMAND));
  3179. // Player[nIndex].m_uLastPingTime = g_SubWorldSet.GetGameTime();
  3180. //}
  3181. void KProtocolProcess::NpcSitCommand(int nIndex, BYTE* pProtocol)
  3182. {
  3183. NPC_SIT_COMMAND *pSitCmd;
  3184. pSitCmd = (NPC_SIT_COMMAND *)pProtocol;
  3185. if (nIndex <= 0 || nIndex >= MAX_PLAYER)
  3186. return;
  3187. if (Player[nIndex].m_nIndex <= 0 || Player[nIndex].m_nIndex >= MAX_NPC)
  3188. return;
  3189. if (pSitCmd->m_btSitFlag)
  3190. Npc[Player[nIndex].m_nIndex].SendCommand(do_sit);
  3191. else
  3192. Npc[Player[nIndex].m_nIndex].SendCommand(do_stand);
  3193. // if (Npc[Player[nIndex].m_nIndex].m_Doing != do_sit)
  3194. // Npc[Player[nIndex].m_nIndex].SendCommand(do_sit);
  3195. // else
  3196. // Npc[Player[nIndex].m_nIndex].SendCommand(do_stand);
  3197. }
  3198. void KProtocolProcess::ObjMouseClick(int nIndex, BYTE* pProtocol)
  3199. {
  3200. if (Player[nIndex].CheckTrading())
  3201. return;
  3202. int nSubWorldIdx, nRegionIdx, nObjIdx;
  3203. int nPlayerX, nPlayerY, nObjX, nObjY;
  3204. OBJ_MOUSE_CLICK_SYNC  *pObj = (OBJ_MOUSE_CLICK_SYNC*)pProtocol;
  3205. nSubWorldIdx = Npc[Player[nIndex].m_nIndex].m_SubWorldIndex;
  3206. nRegionIdx = SubWorld[nSubWorldIdx].FindRegion(pObj->m_dwRegionID);
  3207. if (nRegionIdx < 0)
  3208. return;
  3209. nObjIdx = SubWorld[nSubWorldIdx].m_Region[nRegionIdx].FindObject(pObj->m_nObjID);
  3210. if (nObjIdx <= 0)
  3211. return;
  3212. SubWorld[nSubWorldIdx].Map2Mps(
  3213. Npc[Player[nIndex].m_nIndex].m_RegionIndex,
  3214. Npc[Player[nIndex].m_nIndex].m_MapX,
  3215. Npc[Player[nIndex].m_nIndex].m_MapY,
  3216. Npc[Player[nIndex].m_nIndex].m_OffX,
  3217. Npc[Player[nIndex].m_nIndex].m_OffY,
  3218. &nPlayerX,
  3219. &nPlayerY);
  3220. SubWorld[nSubWorldIdx].Map2Mps(
  3221. nRegionIdx,
  3222. Object[nObjIdx].m_nMapX,
  3223. Object[nObjIdx].m_nMapY,
  3224. Object[nObjIdx].m_nOffX,
  3225. Object[nObjIdx].m_nOffY,
  3226. &nObjX,
  3227. &nObjY);
  3228. /*
  3229. Obj_Kind_MapObj = 0, // 地图物件,主要用于地图动画
  3230. Obj_Kind_Body, // npc 的尸体
  3231. Obj_Kind_Box, // 宝箱
  3232. Obj_Kind_Item, // 掉在地上的装备
  3233. Obj_Kind_Money, // 掉在地上的钱
  3234. Obj_Kind_LoopSound, // 循环音效
  3235. Obj_Kind_RandSound, // 随机音效
  3236. Obj_Kind_Light, // 光源(3D模式中发光的东西)
  3237. Obj_Kind_Door, // 门类
  3238. Obj_Kind_Trap, // 陷阱
  3239. Obj_Kind_Prop, // 小道具,可重生
  3240. Obj_Kind_Num, // 物件的种类数
  3241. */
  3242. switch (Object[nObjIdx].m_nKind)
  3243. {
  3244. case Obj_Kind_Box:
  3245. if (g_GetDistance(nPlayerX, nPlayerY, nObjX, nObjY) > defMAX_EXEC_OBJ_SCRIPT_DISTANCE)
  3246. break;
  3247. if (Object[nObjIdx].m_nState == OBJ_BOX_STATE_CLOSE)
  3248. Object[nObjIdx].ExecScript(nIndex);
  3249. break;
  3250. case Obj_Kind_Door:
  3251. break;
  3252. case Obj_Kind_Prop:
  3253. if (g_GetDistance(nPlayerX, nPlayerY, nObjX, nObjY) > defMAX_EXEC_OBJ_SCRIPT_DISTANCE)
  3254. break;
  3255. if (Object[nObjIdx].m_nState == OBJ_PROP_STATE_DISPLAY)
  3256. Object[nObjIdx].ExecScript(nIndex);
  3257. break;
  3258. }
  3259. }
  3260. void KProtocolProcess::StoreMoneyCommand(int nIndex, BYTE* pProtocol)
  3261. {
  3262. STORE_MONEY_COMMAND* pCommand = (STORE_MONEY_COMMAND *)pProtocol;
  3263. if (pCommand->m_byDir) // 取钱
  3264. Player[nIndex].m_ItemList.ExchangeMoney(room_repository, room_equipment, pCommand->m_dwMoney);
  3265. else // 存钱
  3266. Player[nIndex].m_ItemList.ExchangeMoney(room_equipment, room_repository, pCommand->m_dwMoney);
  3267. }
  3268. void KProtocolProcess::NpcReviveCommand(int nIndex, BYTE* pProtocol)
  3269. {
  3270. // NPC_REVIVE_COMMAND* pCommand = (NPC_REVIVE_COMMAND *)pProtocol;
  3271. Player[nIndex].Revive(REMOTE_REVIVE_TYPE);
  3272. }
  3273. void KProtocolProcess::c2sTradeReplyStart(int nIndex, BYTE* pProtocol)
  3274. {
  3275. Player[nIndex].c2sTradeReplyStart(pProtocol);
  3276. }
  3277. void KProtocolProcess::c2sPKApplyChangeNormalFlag(int nIndex, BYTE* pProtocol)
  3278. {
  3279. PK_APPLY_NORMAL_FLAG_COMMAND *pApply = (PK_APPLY_NORMAL_FLAG_COMMAND*)pProtocol;
  3280. Player[nIndex].m_cPK.SetNormalPKState(pApply->m_btFlag);
  3281. }
  3282. void KProtocolProcess::c2sPKApplyEnmity(int nIndex, BYTE* pProtocol)
  3283. {
  3284. PK_APPLY_ENMITY_COMMAND *pApply = (PK_APPLY_ENMITY_COMMAND*)pProtocol;
  3285. if (Player[nIndex].m_nIndex && !Npc[Player[nIndex].m_nIndex].m_FightMode)
  3286. {
  3287. SHOW_MSG_SYNC sMsg;
  3288. sMsg.ProtocolType = s2c_msgshow;
  3289. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_1;
  3290. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  3291. g_pServer->PackDataToClient(Player[nIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  3292. return;
  3293. }
  3294. if (pApply->m_dwNpcID <= 0 || pApply->m_dwNpcID >= MAX_NPC)
  3295. return;
  3296. int nNpcIdx = Player[nIndex].FindAroundNpc(pApply->m_dwNpcID);
  3297. if (nNpcIdx <= 0)
  3298. return;
  3299. if (Npc[nNpcIdx].m_Kind != kind_player || Npc[nNpcIdx].GetPlayerIdx() <= 0)
  3300. return;
  3301. Player[nIndex].m_cPK.EnmityPKOpen(Npc[nNpcIdx].GetPlayerIdx());
  3302. }
  3303. #define defMAX_VIEW_EQUIP_TIME 30
  3304. void KProtocolProcess::c2sViewEquip(int nIndex, BYTE* pProtocol)
  3305. {
  3306. if (g_SubWorldSet.GetGameTime() - Player[nIndex].m_nViewEquipTime < defMAX_VIEW_EQUIP_TIME)
  3307. return;
  3308. Player[nIndex].m_nViewEquipTime = g_SubWorldSet.GetGameTime();
  3309. VIEW_EQUIP_COMMAND *pView = (VIEW_EQUIP_COMMAND*)pProtocol;
  3310. if (pView->m_dwNpcID == Npc[Player[nIndex].m_nIndex].m_dwID)
  3311. return;
  3312. int nPlayerIdx = Player[nIndex].FindAroundPlayer(pView->m_dwNpcID);
  3313. if (nPlayerIdx <= 0)
  3314. return;
  3315. Player[nPlayerIdx].SendEquipItemInfo(nIndex);
  3316. }
  3317. void KProtocolProcess::LadderQuery(int nIndex, BYTE* pProtocol)
  3318. {
  3319. LADDER_QUERY* pLQ = (LADDER_QUERY *)pProtocol;
  3320. if (nIndex > 0 && nIndex < MAX_PLAYER)
  3321. {
  3322. int lnID = Player[nIndex].m_nNetConnectIdx;
  3323. if (lnID >= 0)
  3324. {
  3325. LADDER_DATA LadderData;
  3326. LadderData.ProtocolType = s2c_ladderresult;
  3327. LadderData.dwLadderID = pLQ->dwLadderID;
  3328. void* pData = (void *)Ladder.GetTopTen(LadderData.dwLadderID);
  3329. if (pData)
  3330. {
  3331. memcpy(LadderData.StatData, pData, sizeof(LadderData.StatData));
  3332. g_pServer->PackDataToClient(lnID, &LadderData, sizeof(LadderData));
  3333. }
  3334. }
  3335. }
  3336. }
  3337. void KProtocolProcess::ItemRepair(int nIndex, BYTE* pProtocol)
  3338. {
  3339. ITEM_REPAIR *pIR = (ITEM_REPAIR *)pProtocol;
  3340. if (nIndex > 0 && nIndex < MAX_PLAYER)
  3341. {
  3342. Player[nIndex].RepairItem(pIR->dwItemID);
  3343. }
  3344. }
  3345. #endif