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

模拟服务器

开发平台:

C/C++

  1. #include "KCore.h"
  2. #include "KThiefSkill.h"
  3. #ifndef _SERVER
  4. #include "../../Represent/iRepresent/iRepresentshell.h"
  5. #include "scene/KScenePlaceC.h"
  6. #include "../../Represent/iRepresent/KRepresentUnit.h"
  7. #include "imgref.h"
  8. #include "KMagicDesc.h"
  9. #include "KOption.h"
  10. #include "KMissle.h"
  11. #endif
  12. KThiefSkill ::KThiefSkill()
  13. {
  14. m_ulAttackRadius = 50;
  15. m_ulDelayPerCast = 40;
  16. m_nSkillCostType = attrib_mana;
  17. #ifndef _SERVER
  18. m_szTargetMovie[0] = 0;
  19. m_szSkillSound[0] = 0;
  20. #endif
  21. m_nCost = 50;
  22. }
  23. KThiefSkill::~KThiefSkill()
  24. {
  25. }
  26. int KThiefSkill::GetSkillId()
  27. {
  28. return 400;
  29. }
  30. const char *KThiefSkill::GetSkillName()
  31. {
  32. return m_szSkillName;
  33. }
  34. int KThiefSkill::GetSkillStyle()
  35. {
  36. return SKILL_SS_Thief;
  37. }
  38. void KThiefSkill::LoadSkillLevelData(unsigned long  ulLevel, int nParam)
  39. {
  40. return;
  41. }
  42. int KThiefSkill::DoSkill(KNpc * pNpc, int nX, int nY)
  43. {
  44. _ASSERT(pNpc);
  45. if (nX != -1 || nY <= 0)
  46. return 0;
  47. pNpc->m_Frames.nTotalFrame = pNpc->m_AttackFrame;
  48. #ifndef _SERVER
  49. if (m_szSkillSpecialFile[0])
  50. pNpc->m_DataRes.SetSpecialSpr(m_szSkillSpecialFile);
  51. pNpc->m_ClientDoing = cdo_stand;
  52. TMissleForShow Show;
  53. Show.nLauncherIndex = pNpc->m_Index;
  54. Show.nNpcIndex = nY;
  55. //KMissle::CreateMissleForShow("\spr\skill\NPC\mag_npc_毒水消失.spr", "30,1,1", "\sound\skill\狂雷震地.wav", &Show);
  56. KMissle::CreateMissleForShow(m_szTargetMovie, m_szTargetMovieParam, m_szSkillSound, &Show);
  57. #endif
  58. pNpc->m_Doing = do_special2;
  59. pNpc->m_ProcessAI = 0;
  60. pNpc->m_Frames.nCurrentFrame = 0;
  61. return 1;
  62. }
  63. #ifdef _SERVER
  64. int KThiefSkill::Cast_Redress(KPlayer * pLaucherPlayer, KPlayer * pTargetPlayer)
  65. {
  66. _ASSERT(pLaucherPlayer && pTargetPlayer);
  67. int nTotalMoney = pTargetPlayer->m_ItemList.GetMoney(room_equipment);
  68. int nLevel1 = Npc[pLaucherPlayer->m_nIndex].m_Level;
  69. int nLevel2 = Npc[pTargetPlayer->m_nIndex].m_Level;
  70. int nOdds = (int) (10 - ((int)abs(nLevel1 - nLevel2)) * 0.1);
  71. int nRand = GetRandomNumber(1, 100);
  72. char szMsg[100];
  73. if (nTotalMoney <= 0 || nRand < nOdds)
  74. {
  75. int nThiefMoney = nTotalMoney * m_nThiefPercent / 100 ;
  76. pTargetPlayer->Pay(nThiefMoney);
  77. sprintf(szMsg, "%s 从你身上偷到%d两银子捐给前线!", Npc[pLaucherPlayer->m_nIndex].Name, nThiefMoney );
  78. KPlayerChat::SendSystemInfo(1, pTargetPlayer->GetPlayerIndex(), "被偷成功 ", (char *) szMsg, strlen(szMsg) );
  79. sprintf(szMsg, "你成功的从%s 那里偷到%d两银子捐给前线!", Npc[pTargetPlayer->m_nIndex].Name, nThiefMoney);
  80. KPlayerChat::SendSystemInfo(1, pLaucherPlayer->GetPlayerIndex(), "偷窃成功 ", (char *) szMsg, strlen(szMsg) );
  81. return TRUE;
  82. }
  83. sprintf(szMsg, "%s 试图偷你的钱,但未成功!", Npc[pLaucherPlayer->m_nIndex].Name);
  84. KPlayerChat::SendSystemInfo(1, pTargetPlayer->GetPlayerIndex(), "被偷未遂", (char *) szMsg, strlen(szMsg) );
  85. sprintf(szMsg, "你偷%s 失败!", Npc[pTargetPlayer->m_nIndex].Name);
  86. KPlayerChat::SendSystemInfo(1, pLaucherPlayer->GetPlayerIndex(), "偷窃未遂", (char *) szMsg, strlen(szMsg) );
  87. return TRUE;
  88. }
  89. int KThiefSkill::Cast_ShowLife(KPlayer * pLauncherPlayer, KPlayer * pTargetPlayer)
  90. {
  91. _ASSERT(pLauncherPlayer && pTargetPlayer);
  92. char szMsg[200];
  93. sprintf(szMsg, "%s 当前生命值情况: %d / %d ", Npc[pTargetPlayer->m_nIndex].Name, Npc[pTargetPlayer->m_nIndex].m_CurrentLife, Npc[pTargetPlayer->m_nIndex].m_CurrentLifeMax);
  94. KPlayerChat::SendSystemInfo(1, pLauncherPlayer->GetPlayerIndex(), "对方情报", (char *) szMsg, strlen(szMsg) );
  95. return TRUE;
  96. }
  97. int KThiefSkill::Cast_ShowMana(KPlayer * pLauncherPlayer, KPlayer * pTargetPlayer)
  98. {
  99. _ASSERT(pLauncherPlayer && pTargetPlayer);
  100. char szMsg[200];
  101. sprintf(szMsg, "%s 当前内力值情况: %d / %d ", Npc[pTargetPlayer->m_nIndex].Name, Npc[pTargetPlayer->m_nIndex].m_CurrentMana, Npc[pTargetPlayer->m_nIndex].m_CurrentManaMax);
  102. KPlayerChat::SendSystemInfo(1, pLauncherPlayer->GetPlayerIndex(), "对方情报", (char *) szMsg, strlen(szMsg) );
  103. return TRUE;
  104. }
  105. int KThiefSkill::Cast_ShowMoney(KPlayer * pLauncherPlayer, KPlayer * pTargetPlayer)
  106. {
  107. _ASSERT(pLauncherPlayer && pTargetPlayer);
  108. char szMsg[200];
  109. sprintf(szMsg, "%s 当前现金情况: %d 两 ", Npc[pTargetPlayer->m_nIndex].Name, pTargetPlayer->m_ItemList.GetMoney(room_equipment));
  110. KPlayerChat::SendSystemInfo(1, pLauncherPlayer->GetPlayerIndex(), "对方情报", (char *) szMsg, strlen(szMsg) );
  111. return TRUE;
  112. }
  113. int KThiefSkill::Cast_RunScript(KPlayer * pLauncherPlayer, KPlayer * pTargetPlayer)
  114. {
  115. _ASSERT(pLauncherPlayer && pTargetPlayer);
  116. if (m_dwParam1)
  117. pTargetPlayer->ExecuteScript(m_dwParam1, "main", pLauncherPlayer->GetPlayerIndex());
  118. return TRUE;
  119. }
  120. #endif
  121. int KThiefSkill::Cast(KPlayer * pLaucherPlayer, KPlayer * pTargetPlayer)
  122. {
  123. #ifdef _SERVER
  124. _ASSERT(pLaucherPlayer && pTargetPlayer);
  125. if (pTargetPlayer && pLaucherPlayer)
  126. {
  127. switch(m_nThiefStyle)
  128. {
  129. case thief_redress:
  130. {
  131. return Cast_Redress(pLaucherPlayer, pTargetPlayer);
  132. }break;
  133. case thief_showlife:
  134. {
  135. return Cast_ShowLife(pLaucherPlayer, pTargetPlayer);
  136. }break;
  137. case thief_showmana:
  138. {
  139. return Cast_ShowMana(pLaucherPlayer, pTargetPlayer);
  140. }break;
  141. case thief_showmoney:
  142. {
  143. return Cast_ShowMoney(pLaucherPlayer, pTargetPlayer);
  144. }break;
  145. case thief_runscript:
  146. {
  147. return Cast_RunScript(pLaucherPlayer, pTargetPlayer);
  148. }
  149. default:
  150. return FALSE;
  151. }
  152. }
  153. #endif
  154. return TRUE;
  155. }
  156. int KThiefSkill::OnSkill(KNpc * pNpc)
  157. {
  158. _ASSERT(pNpc);
  159. if (!pNpc)
  160. return 0;
  161. KPlayer * pLauncherPlayer = NULL;
  162. KPlayer * pTargetPlayer = NULL;
  163. #ifndef _SERVER
  164. pNpc->m_DataRes.SetBlur(FALSE);
  165. #endif
  166. if (pNpc->m_DesX == -1) 
  167. {
  168. if (pNpc->m_DesY <= 0) 
  169. goto Label_ProcessAI1;
  170. //此时该角色已经无效时
  171. if (Npc[pNpc->m_DesY].m_RegionIndex < 0) 
  172. goto Label_ProcessAI1;
  173. }
  174. if (pNpc->m_nPlayerIdx < 0 
  175. || pNpc->m_DesY < 0 
  176. || pNpc->m_DesY >= MAX_NPC 
  177. #ifdef _SERVER
  178. || Npc[pNpc->m_DesY].m_nPlayerIdx < 0
  179. #endif
  180. )
  181. goto Label_ProcessAI1;
  182. pLauncherPlayer = &Player[pNpc->m_nPlayerIdx];
  183. pTargetPlayer = &Player[Npc[pNpc->m_DesY].m_nPlayerIdx];
  184. Cast(pLauncherPlayer, pTargetPlayer);
  185. pNpc->m_SkillList.SetNextCastTime(pNpc->m_ActiveSkillID, SubWorld[pNpc->m_SubWorldIndex].m_dwCurrentTime + GetDelayPerCast());
  186. Label_ProcessAI1:
  187. if (pNpc->m_Frames.nTotalFrame == 0)
  188. {
  189. pNpc->m_ProcessAI = 1;
  190. }
  191. return 1;
  192. }
  193. BOOL KThiefSkill::CanCastSkill  (int nLauncher, int &nParam1, int &nParam2)  const 
  194. {
  195. if (nParam1 != -1)
  196. return FALSE;
  197. if ( nParam2 <= 0 || nParam2 >= MAX_NPC) return FALSE;
  198. NPC_RELATION  Relation = NpcSet.GetRelation(nLauncher, nParam2);
  199. if (Npc[nParam2].m_Index < 0 || Npc[nLauncher].m_Index < 0) 
  200. return FALSE;
  201. if (Npc[nParam2].m_Camp == camp_begin || Npc[nParam2].m_Camp == camp_event)
  202. return FALSE;
  203. #ifdef _SERVER
  204. if (!Npc[nParam2].IsPlayer() || !Npc[nLauncher].IsPlayer())
  205. return FALSE;
  206. #endif
  207. #ifndef _SERVER
  208. int distance = NpcSet.GetDistance(nLauncher, nParam2);
  209. if (distance > (int)m_ulAttackRadius)
  210. return FALSE;
  211. #endif
  212. return TRUE;
  213. }
  214. #ifndef _SERVER
  215. void KThiefSkill::GetDesc(unsigned long ulSkillId, unsigned long ulCurLevel, char * pszMsg, int nOwnerIndex,  bool bGetNextLevelDesc)
  216. {
  217. strcpy(pszMsg, m_szSkillDesc);
  218. }
  219. #endif
  220. BOOL KThiefSkill::LoadSetting(char * szSettingFile)
  221. {
  222. _ASSERT(szSettingFile);
  223. KTabFile TabFile ;
  224. if (!TabFile.Load(szSettingFile))
  225. {
  226. g_DebugLog("无法打开%s", szSettingFile);
  227. return FALSE;
  228. }
  229. TabFile.GetInteger(2, "AttackRadius", 100, (int *)&m_ulAttackRadius);
  230. TabFile.GetInteger(2, "TimePerCast", 100, (int*)&m_ulDelayPerCast);
  231. TabFile.GetInteger(2, "SkillCostType", 0, (int*)&m_nSkillCostType );
  232. TabFile.GetInteger(2, "Cost", 50, (int *)&m_nCost);
  233. TabFile.GetInteger(2, "ThiefPercent", 30, (int *)&m_nThiefPercent);
  234. TabFile.GetInteger(2, "TargetEnemy", TRUE, &m_bTargetEnemy);
  235. TabFile.GetInteger(2, "TargetAlly",  TRUE, &m_bTargetAlly);
  236. TabFile.GetInteger(2, "TargetObj",  FALSE, &m_bTargetObj);
  237. TabFile.GetInteger(2, "ThiefStyle", 0, &m_nThiefStyle);
  238. TabFile.GetString(2, "SkillName", "", m_szSkillName, sizeof(m_szSkillName));
  239. TabFile.GetInteger(2, "CostUsePrecent", 1, &m_bUseCostPercent);
  240. if (m_nThiefStyle == thief_runscript)
  241. {
  242. char szScript[200];
  243. TabFile.GetString(2, "Param1", "", szScript, sizeof(szScript));
  244. strlwr(szScript);
  245. m_dwParam1 =g_FileName2Id(szScript);
  246. }
  247. else
  248. {
  249. TabFile.GetInteger(2, "Param1", 0, (int*)&m_dwParam1);
  250. }
  251. #ifndef _SERVER
  252. TabFile.GetString(2, "Desc", "", m_szSkillDesc, sizeof(m_szSkillDesc));
  253. TabFile.GetString(2, "SkillIcon", "\spr\skill\图标\通用.spr", m_szSkillIcon, sizeof(m_szSkillIcon));
  254. TabFile.GetString(2, "Movie", "", m_szSkillSpecialFile, sizeof(m_szSkillSpecialFile));
  255. TabFile.GetString(2, "TargetMovie", "", m_szTargetMovie, sizeof(m_szTargetMovie));
  256. TabFile.GetString(2, "TargetMovieInfo", "1,1,1", m_szTargetMovieParam, sizeof(m_szTargetMovieParam));
  257. TabFile.GetString(2, "SkillSound", "", m_szSkillSound, sizeof(m_szSkillSound));
  258. #endif
  259. return TRUE;
  260. }
  261. int KThiefSkill::GetSkillCost(void * pParam) const
  262. {
  263. if (m_bUseCostPercent)
  264. {
  265. _ASSERT(pParam);
  266. if (!pParam)
  267. return 10000;
  268. KNpc * pNpc = (KNpc*)pParam;
  269. int nValue = 10000;
  270. if (pNpc->m_Index > 0)
  271. {
  272. switch(m_nSkillCostType)
  273. {
  274. case attrib_mana:
  275. case attrib_maxmana:
  276. {
  277. nValue = pNpc->m_CurrentManaMax;
  278. }
  279. break;
  280. case attrib_stamina:
  281. case attrib_maxstamina:
  282. {
  283. nValue = pNpc->m_CurrentStaminaMax;
  284. }
  285. break;
  286. case attrib_life:
  287. case attrib_maxlife:
  288. {
  289. nValue = pNpc->m_CurrentLifeMax;
  290. }break;
  291. default:
  292. nValue = 10000;
  293. }
  294. nValue = m_nCost * nValue / 100;
  295. }
  296. else
  297. {
  298. return nValue;
  299. }
  300. }
  301. else
  302. return m_nCost;
  303. return 10000;
  304. }
  305. #ifndef _SERVER
  306. void KThiefSkill::DrawSkillIcon(int x, int y, int Width, int Height)  
  307. {
  308. if (!m_szSkillIcon[0]) return ;
  309. m_RUIconImage.nType = ISI_T_SPR;
  310. m_RUIconImage.Color.Color_b.a = 255;
  311. m_RUIconImage.bRenderStyle = IMAGE_RENDER_STYLE_ALPHA;
  312. m_RUIconImage.uImage = 0;
  313. m_RUIconImage.nISPosition = IMAGE_IS_POSITION_INIT;
  314. m_RUIconImage.bRenderFlag = 0;
  315. strcpy(m_RUIconImage.szImage, m_szSkillIcon);
  316. m_RUIconImage.oPosition.nX = x;
  317. m_RUIconImage.oPosition.nY = y;
  318. m_RUIconImage.oPosition.nZ = 0;
  319. m_RUIconImage.nFrame = 0;
  320. g_pRepresent->DrawPrimitives(1, &m_RUIconImage, RU_T_IMAGE, 1);
  321. }
  322. #endif