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

模拟服务器

开发平台:

C/C++

  1. //---------------------------------------------------------------------------
  2. // Sword3 Engine (c) 2003 by Kingsoft
  3. //
  4. // File: KPlayerPK.cpp
  5. // Date: 2003.07.15
  6. // Code: 边城浪子
  7. // Desc: PlayerPK Class
  8. //---------------------------------------------------------------------------
  9. #include "KCore.h"
  10. #include "KPlayer.h"
  11. #include "KPlayerDef.h"
  12. #include "KPlayerPK.h"
  13. #ifndef _SERVER
  14. #include "CoreShell.h"
  15. #endif
  16. #ifdef _SERVER
  17. //-------------------------------------------------------------------------
  18. // 功能:构造函数
  19. //-------------------------------------------------------------------------
  20. KPlayerPK::KPlayerPK()
  21. {
  22. m_nPlayerIndex = 0;
  23. }
  24. //-------------------------------------------------------------------------
  25. // 功能:初始化
  26. //-------------------------------------------------------------------------
  27. void KPlayerPK::Init(int nPlayerIdx)
  28. {
  29. this->m_nPlayerIndex = nPlayerIdx;
  30. m_nNormalPKFlag = 1;
  31. m_nEnmityPKState = enumPK_ENMITY_STATE_CLOSE;
  32. m_nEnmityPKAim = 0;
  33. m_nEnmityPKTime = 0;
  34. m_nEnmityPKLaunchFlag = 0;
  35. m_nExercisePKFlag = 0;
  36. m_nExercisePKAim = 0;
  37. m_nPKValue = 0;
  38. }
  39. void KPlayerPK::Active()
  40. {
  41. EnmityPKCountDown();
  42. }
  43. //-------------------------------------------------------------------------
  44. // 功能:设定正常PK状态 TRUE 打开,可以砍人  FALSE 关闭,不可以砍人
  45. //-------------------------------------------------------------------------
  46. void KPlayerPK::SetNormalPKState(BOOL bFlag)
  47. {
  48. m_nNormalPKFlag = bFlag;
  49. PK_NORMAL_FLAG_SYNC sFlag;
  50. sFlag.ProtocolType = s2c_pksyncnormalflag;
  51. sFlag.m_btFlag = m_nNormalPKFlag;
  52. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sFlag, sizeof(PK_NORMAL_FLAG_SYNC));
  53. }
  54. //-------------------------------------------------------------------------
  55. // 功能:获得正常PK状态 TRUE 打开,可以砍人  FALSE 关闭,不可以砍人
  56. //-------------------------------------------------------------------------
  57. BOOL KPlayerPK::GetNormalPKState()
  58. {
  59. return this->m_nNormalPKFlag;
  60. }
  61. //-------------------------------------------------------------------------
  62. // 功能:关闭仇杀PK
  63. //-------------------------------------------------------------------------
  64. void KPlayerPK::EnmityPKClose()
  65. {
  66. if (m_nEnmityPKState == enumPK_ENMITY_STATE_CLOSE)
  67. return;
  68. PK_ENMITY_STATE_SYNC sState;
  69. sState.ProtocolType = s2c_pksyncenmitystate;
  70. sState.m_btState = enumPK_ENMITY_STATE_CLOSE;
  71. sState.m_dwNpcID = 0;
  72. sState.m_wLength = sizeof(PK_ENMITY_STATE_SYNC) - 1 - sizeof(sState.m_szName);
  73. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  74. if (m_nEnmityPKAim > 0 && m_nEnmityPKAim < MAX_PLAYER)
  75. {
  76. g_pServer->PackDataToClient(Player[m_nEnmityPKAim].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  77. Player[m_nEnmityPKAim].m_cPK.m_nEnmityPKState = enumPK_ENMITY_STATE_CLOSE;
  78. Player[m_nEnmityPKAim].m_cPK.m_nEnmityPKAim = 0;
  79. Player[m_nEnmityPKAim].m_cPK.m_nEnmityPKTime = 0;
  80. }
  81. this->m_nEnmityPKState = enumPK_ENMITY_STATE_CLOSE;
  82. this->m_nEnmityPKAim = 0;
  83. this->m_nEnmityPKTime = 0;
  84. m_nEnmityPKLaunchFlag = 0;
  85. }
  86. //-------------------------------------------------------------------------
  87. // 功能:仇杀PK开始
  88. //-------------------------------------------------------------------------
  89. BOOL KPlayerPK::EnmityPKOpen(int nAim)
  90. {
  91. // 出错
  92. if (nAim <= 0 || nAim >= MAX_PLAYER || Player[nAim].m_nIndex < 1)
  93. return FALSE;
  94. // 非战斗模式
  95. if (!Npc[Player[m_nPlayerIndex].m_nIndex].m_FightMode)
  96. {
  97. SHOW_MSG_SYNC sMsg;
  98. sMsg.ProtocolType = s2c_msgshow;
  99. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_1;
  100. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  101. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  102. return FALSE;
  103. }
  104. if (!Npc[Player[nAim].m_nIndex].m_FightMode)
  105. {
  106. SHOW_MSG_SYNC sMsg;
  107. sMsg.ProtocolType = s2c_msgshow;
  108. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_6;
  109. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  110. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  111. return FALSE;
  112. }
  113. // 自己是新手
  114. if (Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp == camp_begin)
  115. {
  116. SHOW_MSG_SYNC sMsg;
  117. sMsg.ProtocolType = s2c_msgshow;
  118. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_2;
  119. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  120. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  121. return FALSE;
  122. }
  123. // 正在切磋
  124. if (m_nExercisePKFlag == TRUE)
  125. {
  126. SHOW_MSG_SYNC sMsg;
  127. sMsg.ProtocolType = s2c_msgshow;
  128. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_3;
  129. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  130. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  131. return FALSE;
  132. }
  133. // 对方正在切磋
  134. if (Player[nAim].m_cPK.GetExercisePKState())
  135. {
  136. SHOW_MSG_SYNC sMsg;
  137. sMsg.ProtocolType = s2c_msgshow;
  138. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_7;
  139. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  140. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  141. return FALSE;
  142. }
  143. // 正在仇杀
  144. if (m_nEnmityPKState != enumPK_ENMITY_STATE_CLOSE)
  145. {
  146. SHOW_MSG_SYNC sMsg;
  147. sMsg.ProtocolType = s2c_msgshow;
  148. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_4;
  149. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  150. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  151. return FALSE;
  152. }
  153. // 对方是新手
  154. if (Npc[Player[nAim].m_nIndex].m_Camp == camp_begin)
  155. {
  156. SHOW_MSG_SYNC sMsg;
  157. sMsg.ProtocolType = s2c_msgshow;
  158. sMsg.m_wMsgID = enumMSG_ID_PK_ERROR_5;
  159. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  160. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  161. return FALSE;
  162. }
  163. Player[nAim].m_cPK.EnmityPKClose();
  164. Player[nAim].m_cPK.m_nEnmityPKState = enumPK_ENMITY_STATE_TIME;
  165. Player[nAim].m_cPK.m_nEnmityPKAim = m_nPlayerIndex;
  166. Player[nAim].m_cPK.m_nEnmityPKTime = PK_ANMITY_TIME;
  167. Player[nAim].m_cPK.m_nEnmityPKLaunchFlag = 0;
  168. m_nEnmityPKState = enumPK_ENMITY_STATE_TIME;
  169. m_nEnmityPKAim = nAim;
  170. m_nEnmityPKTime = PK_ANMITY_TIME;
  171. m_nEnmityPKLaunchFlag = 1;
  172. PK_ENMITY_STATE_SYNC sState;
  173. sState.ProtocolType = s2c_pksyncenmitystate;
  174. sState.m_btState = enumPK_ENMITY_STATE_TIME;
  175. sState.m_dwNpcID = Npc[Player[m_nPlayerIndex].m_nIndex].m_dwID;
  176. strcpy(sState.m_szName, Npc[Player[m_nPlayerIndex].m_nIndex].Name);
  177. sState.m_wLength = sizeof(PK_ENMITY_STATE_SYNC) - 1 - sizeof(sState.m_szName) + strlen(sState.m_szName);
  178. g_pServer->PackDataToClient(Player[nAim].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  179. sState.m_dwNpcID = Npc[Player[nAim].m_nIndex].m_dwID;
  180. strcpy(sState.m_szName, Npc[Player[nAim].m_nIndex].Name);
  181. sState.m_wLength = sizeof(PK_ENMITY_STATE_SYNC) - 1 - sizeof(sState.m_szName) + strlen(sState.m_szName);
  182. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  183. return TRUE;
  184. }
  185. //-------------------------------------------------------------------------
  186. // 功能:获得仇杀状态,对应 enumPK_ANMITY_STATE
  187. //-------------------------------------------------------------------------
  188. int KPlayerPK::GetEnmityPKState()
  189. {
  190. return this->m_nEnmityPKState;
  191. }
  192. //-------------------------------------------------------------------------
  193. // 功能:获得仇杀目标 if 目标==0 不在仇杀状态 else 得到仇杀目标
  194. //-------------------------------------------------------------------------
  195. int KPlayerPK::GetEnmityPKAim()
  196. {
  197. return this->m_nEnmityPKAim;
  198. }
  199. //-------------------------------------------------------------------------
  200. // 功能:关闭切磋PK
  201. //-------------------------------------------------------------------------
  202. void KPlayerPK::ExercisePKClose()
  203. {
  204. if (m_nExercisePKFlag == FALSE)
  205. return;
  206. PK_EXERCISE_STATE_SYNC sState;
  207. sState.ProtocolType = s2c_pksyncexercisestate;
  208. sState.m_btState = 0;
  209. sState.m_dwNpcID = 0;
  210. sState.m_wLength = sizeof(PK_EXERCISE_STATE_SYNC) - 1 - sizeof(sState.m_szName);
  211. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  212. if (m_nExercisePKAim > 0 && m_nExercisePKAim < MAX_PLAYER)
  213. {
  214. g_pServer->PackDataToClient(Player[m_nExercisePKAim].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  215. Player[m_nExercisePKAim].m_cPK.m_nExercisePKFlag = FALSE;
  216. Player[m_nExercisePKAim].m_cPK.m_nExercisePKAim = 0;
  217. }
  218. this->m_nExercisePKFlag = FALSE;
  219. this->m_nExercisePKAim = 0;
  220. }
  221. //-------------------------------------------------------------------------
  222. // 功能:打开切磋PK
  223. //-------------------------------------------------------------------------
  224. BOOL KPlayerPK::ExercisePKOpen(int nAim)
  225. {
  226. // 自己是新手
  227. if (Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp == camp_begin)
  228. return FALSE;
  229. // 正在切磋
  230. if (m_nExercisePKFlag == TRUE)
  231. return FALSE;
  232. // 出错
  233. if (nAim <= 0 || nAim >= MAX_PLAYER || Player[nAim].m_nIndex < 1)
  234. return FALSE;
  235. // 对方是新手
  236. if (Npc[Player[nAim].m_nIndex].m_Camp == camp_begin)
  237. return FALSE;
  238. this->EnmityPKClose();
  239. Player[nAim].m_cPK.EnmityPKClose();
  240. this->m_nExercisePKFlag = TRUE;
  241. this->m_nExercisePKAim = nAim;
  242. Player[nAim].m_cPK.m_nExercisePKFlag = TRUE;
  243. Player[nAim].m_cPK.m_nExercisePKAim = this->m_nPlayerIndex;
  244. PK_EXERCISE_STATE_SYNC sState;
  245. sState.ProtocolType = s2c_pksyncexercisestate;
  246. sState.m_btState = 1;
  247. sState.m_dwNpcID = Npc[Player[m_nPlayerIndex].m_nIndex].m_dwID;
  248. strcpy(sState.m_szName, Npc[Player[m_nPlayerIndex].m_nIndex].Name);
  249. sState.m_wLength = sizeof(PK_EXERCISE_STATE_SYNC) - 1 - sizeof(sState.m_szName) + strlen(sState.m_szName);
  250. g_pServer->PackDataToClient(Player[nAim].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  251. sState.m_dwNpcID = Npc[Player[nAim].m_nIndex].m_dwID;
  252. strcpy(sState.m_szName, Npc[Player[nAim].m_nIndex].Name);
  253. sState.m_wLength = sizeof(PK_EXERCISE_STATE_SYNC) - 1 - sizeof(sState.m_szName) + strlen(sState.m_szName);
  254. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  255. return TRUE;
  256. }
  257. //-------------------------------------------------------------------------
  258. // 功能:获得切磋目标 if 目标==0 不在切磋状态 else 得到切磋目标
  259. //-------------------------------------------------------------------------
  260. int KPlayerPK::GetExercisePKAim()
  261. {
  262. return this->m_nExercisePKAim;
  263. }
  264. //-------------------------------------------------------------------------
  265. // 功能:设定PK值
  266. //-------------------------------------------------------------------------
  267. void KPlayerPK::SetPKValue(int nValue)
  268. {
  269. this->m_nPKValue = (nValue < 0 ? 0 : nValue);
  270. if (m_nPKValue > MAX_DEATH_PUNISH_PK_VALUE)
  271. m_nPKValue = MAX_DEATH_PUNISH_PK_VALUE;
  272. PK_VALUE_SYNC sValue;
  273. sValue.ProtocolType = s2c_pksyncpkvalue;
  274. sValue.m_nPKValue = m_nPKValue;
  275. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sValue, sizeof(PK_VALUE_SYNC));
  276. }
  277. //-------------------------------------------------------------------------
  278. // 功能:获得PK值
  279. //-------------------------------------------------------------------------
  280. int KPlayerPK::GetPKValue()
  281. {
  282. return m_nPKValue;
  283. }
  284. //-------------------------------------------------------------------------
  285. // 功能:增加(或减少)PK值,PK值最多减少到0
  286. //-------------------------------------------------------------------------
  287. void KPlayerPK::AddPKValue(int nAdd)
  288. {
  289. m_nPKValue += nAdd;
  290. if (m_nPKValue < 0)
  291. m_nPKValue = 0;
  292. if (m_nPKValue > MAX_DEATH_PUNISH_PK_VALUE)
  293. m_nPKValue = MAX_DEATH_PUNISH_PK_VALUE;
  294. PK_VALUE_SYNC sValue;
  295. sValue.ProtocolType = s2c_pksyncpkvalue;
  296. sValue.m_nPKValue = m_nPKValue;
  297. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sValue, sizeof(PK_VALUE_SYNC));
  298. }
  299. //-------------------------------------------------------------------------
  300. // 功能:关闭仇杀PK和切磋PK
  301. //-------------------------------------------------------------------------
  302. void KPlayerPK::CloseAll()
  303. {
  304. ExercisePKClose();
  305. EnmityPKClose();
  306. }
  307. //-------------------------------------------------------------------------
  308. // 功能:仇杀倒计时
  309. //-------------------------------------------------------------------------
  310. void KPlayerPK::EnmityPKCountDown()
  311. {
  312. if (m_nEnmityPKState == enumPK_ENMITY_STATE_TIME)
  313. {
  314. m_nEnmityPKTime--;
  315. if (m_nEnmityPKTime > 0)
  316. return;
  317. m_nEnmityPKTime = PK_ANMITY_CLOSE_TIME;
  318. m_nEnmityPKState = enumPK_ENMITY_STATE_PKING;
  319. if (Player[m_nEnmityPKAim].m_nIndex <= 0)
  320. return;
  321. PK_ENMITY_STATE_SYNC sState;
  322. sState.ProtocolType = s2c_pksyncenmitystate;
  323. sState.m_btState = enumPK_ENMITY_STATE_PKING;
  324. sState.m_dwNpcID = Npc[Player[m_nEnmityPKAim].m_nIndex].m_dwID;
  325. strcpy(sState.m_szName, Npc[Player[m_nEnmityPKAim].m_nIndex].Name);
  326. sState.m_wLength = sizeof(PK_ENMITY_STATE_SYNC) - 1 - sizeof(sState.m_szName) + strlen(sState.m_szName);
  327. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, (BYTE*)&sState, sState.m_wLength + 1);
  328. }
  329. else if (m_nEnmityPKState == enumPK_ENMITY_STATE_PKING)
  330. {
  331. m_nEnmityPKTime--;
  332. if (m_nEnmityPKTime > 0)
  333. return;
  334. m_nEnmityPKTime = 0;
  335. ExercisePKClose();
  336. }
  337. }
  338. #endif
  339. #ifndef _SERVER
  340. //-------------------------------------------------------------------------
  341. // 功能:初始化
  342. //-------------------------------------------------------------------------
  343. void KPlayerPK::Init()
  344. {
  345. // m_nNormalPKFlag = 1;
  346. m_nEnmityPKState = enumPK_ENMITY_STATE_CLOSE;
  347. m_nEnmityPKAim = 0;
  348. m_nEnmityPKTime = 0;
  349. m_szEnmityAimName[0] = 0;
  350. m_nExercisePKFlag = 0;
  351. m_nExercisePKAim = 0;
  352. m_szExerciseAimName[0] = 0;
  353. // m_nPKValue = 0;
  354. }
  355. void KPlayerPK::Active()
  356. {
  357. EnmityPKCountDown();
  358. }
  359. //-------------------------------------------------------------------------
  360. // 功能:设定正常PK状态 TRUE 打开,可以砍人  FALSE 关闭,不可以砍人
  361. //-------------------------------------------------------------------------
  362. void KPlayerPK::SetNormalPKState(BOOL bFlag, BOOL bShowMsg/* = TRUE*/)
  363. {
  364. if (m_nNormalPKFlag == bFlag)
  365. return;
  366. m_nNormalPKFlag = bFlag;
  367. CoreDataChanged(GDCNI_PK_SETTING, 0, bFlag);
  368. if (bShowMsg)
  369. {
  370. KSystemMessage sMsg;
  371. if (bFlag)
  372. sprintf(sMsg.szMessage, MSG_PK_NORMAL_FLAG_OPEN);
  373. else
  374. sprintf(sMsg.szMessage, MSG_PK_NORMAL_FLAG_CLOSE);
  375. sMsg.eType = SMT_NORMAL;
  376. sMsg.byConfirmType = SMCT_NONE;
  377. sMsg.byPriority = 0;
  378. sMsg.byParamSize = 0;
  379. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  380. }
  381. }
  382. //-------------------------------------------------------------------------
  383. // 功能:向服务器申请打开、关闭正常PK状态
  384. //-------------------------------------------------------------------------
  385. void KPlayerPK::ApplySetNormalPKState(BOOL bFlag)
  386. {
  387. // SetNormalPKState(bFlag, FALSE);
  388. PK_APPLY_NORMAL_FLAG_COMMAND sApply;
  389. sApply.ProtocolType = c2s_pkapplychangenormalflag;
  390. sApply.m_btFlag = bFlag;
  391. if (g_pClient)
  392. g_pClient->SendPackToServer(&sApply, sizeof(PK_APPLY_NORMAL_FLAG_COMMAND));
  393. }
  394. //-------------------------------------------------------------------------
  395. // 功能:获得正常PK状态 TRUE 打开,可以砍人  FALSE 关闭,不可以砍人
  396. //-------------------------------------------------------------------------
  397. BOOL KPlayerPK::GetNormalPKState()
  398. {
  399. return this->m_nNormalPKFlag;
  400. }
  401. //-------------------------------------------------------------------------
  402. // 功能:向服务器申请仇杀某人
  403. //-------------------------------------------------------------------------
  404. void KPlayerPK::ApplyEnmityPK(char *lpszName)
  405. {
  406. if (!lpszName || !lpszName[0])
  407. return;
  408. int nNpcIdx;
  409. nNpcIdx = NpcSet.SearchName(lpszName);
  410. if (nNpcIdx <= 0)
  411. return;
  412. ApplyEnmityPK(Npc[nNpcIdx].m_dwID);
  413. }
  414. //-------------------------------------------------------------------------
  415. // 功能:向服务器申请仇杀某人
  416. //-------------------------------------------------------------------------
  417. void KPlayerPK::ApplyEnmityPK(int nNpcID)
  418. {
  419. if (m_nEnmityPKState != enumPK_ENMITY_STATE_CLOSE)
  420. {
  421. KSystemMessage sMsg;
  422. sprintf(sMsg.szMessage, MSG_PK_ERROR_4);
  423. sMsg.eType = SMT_NORMAL;
  424. sMsg.byConfirmType = SMCT_NONE;
  425. sMsg.byPriority = 0;
  426. sMsg.byParamSize = 0;
  427. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  428. return;
  429. }
  430. if (!Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_FightMode)
  431. {
  432. KSystemMessage sMsg;
  433. sprintf(sMsg.szMessage, MSG_PK_ERROR_1);
  434. sMsg.eType = SMT_NORMAL;
  435. sMsg.byConfirmType = SMCT_NONE;
  436. sMsg.byPriority = 0;
  437. sMsg.byParamSize = 0;
  438. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  439. return;
  440. }
  441. int nIdx = NpcSet.SearchID(nNpcID);
  442. if (nIdx == 0 || Npc[nIdx].m_Kind != kind_player)
  443. return;
  444. PK_APPLY_ENMITY_COMMAND sApply;
  445. sApply.ProtocolType = c2s_pkapplyenmity;
  446. sApply.m_dwNpcID = nNpcID;
  447. if (g_pClient)
  448. g_pClient->SendPackToServer(&sApply, sizeof(PK_APPLY_ENMITY_COMMAND));
  449. }
  450. //-------------------------------------------------------------------------
  451. // 功能:设定仇杀PK状态
  452. //-------------------------------------------------------------------------
  453. void KPlayerPK::SetEnmityPKState(int nState, int nNpcID/* = 0*/, char *lpszName/* = NULL*/)
  454. {
  455. if (nState == enumPK_ENMITY_STATE_CLOSE)
  456. {
  457. if (m_nEnmityPKState != enumPK_ENMITY_STATE_CLOSE)
  458. {
  459. KSystemMessage sMsg;
  460. sMsg.eType = SMT_NORMAL;
  461. sMsg.byConfirmType = SMCT_NONE;
  462. sMsg.byPriority = 0;
  463. sMsg.byParamSize = 0;
  464. sprintf(sMsg.szMessage, MSG_PK_ENMITY_CLOSE);
  465. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  466. }
  467. m_nEnmityPKState = enumPK_ENMITY_STATE_CLOSE;
  468. m_nEnmityPKAim = 0;
  469. m_nEnmityPKTime = 0;
  470. m_szEnmityAimName[0] = 0;
  471. }
  472. else if (nState == enumPK_ENMITY_STATE_TIME)
  473. {
  474. m_nEnmityPKState = enumPK_ENMITY_STATE_CLOSE;
  475. m_nEnmityPKAim = nNpcID;
  476. m_nEnmityPKTime = PK_ANMITY_TIME;
  477. m_szEnmityAimName[0] = 0;
  478. if (lpszName)
  479. strcpy(m_szEnmityAimName, lpszName);
  480. KSystemMessage sMsg;
  481. sMsg.eType = SMT_NORMAL;
  482. sMsg.byConfirmType = SMCT_NONE;
  483. sMsg.byPriority = 0;
  484. sMsg.byParamSize = 0;
  485. sprintf(sMsg.szMessage, MSG_PK_ENMITY_SUCCESS_1, m_szEnmityAimName);
  486. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  487. sprintf(sMsg.szMessage, MSG_PK_ENMITY_SUCCESS_2);
  488. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  489. }
  490. else // if (nState == enumPK_ENMITY_STATE_PKING)
  491. {
  492. m_nEnmityPKState = enumPK_ENMITY_STATE_PKING;
  493. m_nEnmityPKTime = 0;
  494. if (nNpcID > 0)
  495. m_nEnmityPKAim = nNpcID;
  496. if (lpszName)
  497. strcpy(m_szEnmityAimName, lpszName);
  498. KSystemMessage sMsg;
  499. sMsg.eType = SMT_NORMAL;
  500. sMsg.byConfirmType = SMCT_NONE;
  501. sMsg.byPriority = 0;
  502. sMsg.byParamSize = 0;
  503. sprintf(sMsg.szMessage, MSG_PK_ENMITY_OPEN);
  504. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  505. }
  506. }
  507. //-------------------------------------------------------------------------
  508. // 功能:仇杀倒计时
  509. //-------------------------------------------------------------------------
  510. void KPlayerPK::EnmityPKCountDown()
  511. {
  512. if (m_nEnmityPKState == enumPK_ENMITY_STATE_TIME)
  513. {
  514. m_nEnmityPKTime--;
  515. if (m_nEnmityPKTime < 0)
  516. m_nEnmityPKTime = 0;
  517. }
  518. }
  519. //-------------------------------------------------------------------------
  520. // 功能:设定切磋状态
  521. //-------------------------------------------------------------------------
  522. void KPlayerPK::SetExercisePKState(int nState, int nNpcID/* = 0*/, char *lpszName/* = NULL*/)
  523. {
  524. SetEnmityPKState(enumPK_ENMITY_STATE_CLOSE);
  525. if (nState)
  526. {
  527. m_nExercisePKFlag = 1;
  528. m_nExercisePKAim = nNpcID;
  529. m_szExerciseAimName[0] = 0;
  530. if (lpszName)
  531. strcpy(m_szExerciseAimName, lpszName);
  532. }
  533. else
  534. {
  535. m_nExercisePKFlag = 0;
  536. m_nExercisePKAim = 0;
  537. m_szExerciseAimName[0] = 0;
  538. }
  539. }
  540. //-------------------------------------------------------------------------
  541. // 功能:设定PK值
  542. //-------------------------------------------------------------------------
  543. void KPlayerPK::SetPKValue(int nValue)
  544. {
  545. if (m_nPKValue == nValue)
  546. return;
  547. this->m_nPKValue = (nValue < 0 ? 0 : nValue);
  548. if (m_nPKValue > MAX_DEATH_PUNISH_PK_VALUE)
  549. m_nPKValue = MAX_DEATH_PUNISH_PK_VALUE;
  550. KSystemMessage sMsg;
  551. sprintf(sMsg.szMessage, MSG_PK_VALUE, m_nPKValue);
  552. sMsg.eType = SMT_NORMAL;
  553. sMsg.byConfirmType = SMCT_NONE;
  554. sMsg.byPriority = 0;
  555. sMsg.byParamSize = 0;
  556. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  557. }
  558. #endif