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

模拟服务器

开发平台:

C/C++

  1. //---------------------------------------------------------------------------
  2. // Sword3 Engine (c) 1999-2000 by Kingsoft
  3. //
  4. // File: KNpcGold.cpp
  5. // Date: 2003.07.23
  6. // Code: 边城浪子
  7. // Desc: KNpcGold Class
  8. //---------------------------------------------------------------------------
  9. #include "KCore.h"
  10. #include "KNpcTemplate.h"
  11. #include "KNpc.h"
  12. #include "KNpcGold.h"
  13. #define defNPC_GOLD_SKILL_NO 5
  14. #define defNPC_GOLD_RATE 20
  15. #ifdef _SERVER
  16. extern KLuaScript *g_pNpcLevelScript;
  17. #endif
  18. void KNpcGold::Init(int nIdx)
  19. {
  20. this->m_nNpcIdx = nIdx;
  21. this->m_nIsGold = FALSE;
  22. this->m_nIsGolding = FALSE;
  23. this->m_nGoldType = 0;
  24. this->m_dwSkill5ID = 0;
  25. this->m_nSkill5Level = 0;
  26. this->m_nFireResist = 0;
  27. this->m_nFireResistMax = 0;
  28. this->m_nColdResist = 0;
  29. this->m_nColdResistMax = 0;
  30. this->m_nLightingResist = 0;
  31. this->m_nLightingResistMax = 0;
  32. this->m_nPoisonResist = 0;
  33. this->m_nPoisonResistMax = 0;
  34. this->m_nPhycicsResist = 0;
  35. this->m_nPhycicsResistMax = 0;
  36. }
  37. //---------------------------------------------------------------------------
  38. // 功能:设定是否为黄金怪物
  39. //---------------------------------------------------------------------------
  40. void KNpcGold::SetGoldType(BOOL bFlag)
  41. {
  42. this->m_nIsGold = (bFlag != 0 ? 1 : 0);
  43. }
  44. //---------------------------------------------------------------------------
  45. // 功能:设定类型为黄金怪物,同时备份相应数据
  46. //---------------------------------------------------------------------------
  47. void KNpcGold::SetGoldTypeAndBackData()
  48. {
  49. m_nIsGold = 1;
  50. m_nIsGolding = 0;
  51. m_nGoldType = 0;
  52. m_nFireResist = Npc[m_nNpcIdx].m_CurrentFireResist;
  53. m_nFireResistMax = Npc[m_nNpcIdx].m_CurrentFireResistMax;
  54. m_nColdResist = Npc[m_nNpcIdx].m_CurrentColdResist;
  55. m_nColdResistMax = Npc[m_nNpcIdx].m_CurrentColdResistMax;
  56. m_nLightingResist = Npc[m_nNpcIdx].m_CurrentLightResist;
  57. m_nLightingResistMax = Npc[m_nNpcIdx].m_CurrentLightResistMax;
  58. m_nPoisonResist = Npc[m_nNpcIdx].m_CurrentPoisonResist;
  59. m_nPoisonResistMax = Npc[m_nNpcIdx].m_CurrentPoisonResistMax;
  60. m_nPhycicsResist = Npc[m_nNpcIdx].m_CurrentPhysicsResist;
  61. m_nPhycicsResistMax = Npc[m_nNpcIdx].m_CurrentPhysicsResistMax;
  62. }
  63. //---------------------------------------------------------------------------
  64. // 功能:恢复旧数据,变成普通npc
  65. //---------------------------------------------------------------------------
  66. void KNpcGold::RecoverBackData()
  67. {
  68. if (!m_nIsGold || !m_nIsGolding)
  69. return;
  70. m_nIsGolding = 0;
  71. // 用备份数据覆盖
  72. Npc[m_nNpcIdx].m_CurrentFireResist = m_nFireResist;
  73. Npc[m_nNpcIdx].m_CurrentFireResistMax = m_nFireResistMax;
  74. Npc[m_nNpcIdx].m_CurrentColdResist = m_nColdResist;
  75. Npc[m_nNpcIdx].m_CurrentColdResistMax = m_nColdResistMax;
  76. Npc[m_nNpcIdx].m_CurrentLightResist = m_nLightingResist;
  77. Npc[m_nNpcIdx].m_CurrentLightResistMax = m_nLightingResistMax;
  78. Npc[m_nNpcIdx].m_CurrentPoisonResist = m_nPoisonResist;
  79. Npc[m_nNpcIdx].m_CurrentPoisonResistMax = m_nPoisonResistMax;
  80. Npc[m_nNpcIdx].m_CurrentPhysicsResist = m_nPhycicsResist;
  81. Npc[m_nNpcIdx].m_CurrentPhysicsResistMax = m_nPhycicsResistMax;
  82. #ifdef _SERVER
  83. Npc[m_nNpcIdx].m_SkillList.RemoveNpcSkill(defNPC_GOLD_SKILL_NO);
  84. Npc[m_nNpcIdx].SetAuraSkill(0);
  85. #endif
  86. if (m_nGoldType < 0 || m_nGoldType >= NpcSet.m_cGoldTemplate.m_nEffectTypeNum)
  87. return;
  88. KNpcGoldTemplateInfo *pInfo = &NpcSet.m_cGoldTemplate.m_sInfo[m_nGoldType];
  89. // 按比例缩小
  90. Npc[m_nNpcIdx].m_Experience /= pInfo->m_nExp;
  91. Npc[m_nNpcIdx].m_CurrentLifeMax /= pInfo->m_nLife;
  92. Npc[m_nNpcIdx].m_CurrentLifeReplenish /= pInfo->m_nLifeReplenish;
  93. Npc[m_nNpcIdx].m_CurrentAttackRating /= pInfo->m_nAttackRating;
  94. Npc[m_nNpcIdx].m_CurrentDefend /= pInfo->m_nDefense;
  95. Npc[m_nNpcIdx].m_PhysicsDamage.nValue[0] /= pInfo->m_nMinDamage;
  96. Npc[m_nNpcIdx].m_PhysicsDamage.nValue[2] /= pInfo->m_nMaxDamage;
  97. // 扣点数
  98. Npc[m_nNpcIdx].m_CurrentTreasure -= pInfo->m_nTreasure;
  99. Npc[m_nNpcIdx].m_CurrentWalkSpeed -= pInfo->m_nWalkSpeed;
  100. Npc[m_nNpcIdx].m_CurrentRunSpeed -= pInfo->m_nRunSpeed;
  101. Npc[m_nNpcIdx].m_CurrentAttackSpeed -= pInfo->m_nAttackSpeed;
  102. Npc[m_nNpcIdx].m_CurrentCastSpeed -= pInfo->m_nCastSpeed;
  103. }
  104. //---------------------------------------------------------------------------
  105. // 功能:按一定概率变成黄金怪物
  106. //---------------------------------------------------------------------------
  107. void KNpcGold::RandChangeGold()
  108. {
  109. if (!m_nIsGold || this->m_nIsGolding)
  110. return;
  111. if (g_Random(100) >= defNPC_GOLD_RATE)
  112. return;
  113. if (NpcSet.m_cGoldTemplate.m_nEffectTypeNum <= 0)
  114. return;
  115. m_nGoldType = g_Random(NpcSet.m_cGoldTemplate.m_nEffectTypeNum);
  116. m_nIsGolding = 1;
  117. KNpcGoldTemplateInfo *pInfo = &NpcSet.m_cGoldTemplate.m_sInfo[m_nGoldType];
  118. // 用模板数据直接辅值
  119. Npc[m_nNpcIdx].m_CurrentFireResist = pInfo->m_nFireResist;
  120. Npc[m_nNpcIdx].m_CurrentFireResistMax = pInfo->m_nFireResistMax;
  121. Npc[m_nNpcIdx].m_CurrentColdResist = pInfo->m_nColdResist;
  122. Npc[m_nNpcIdx].m_CurrentColdResistMax = pInfo->m_nColdResistMax;
  123. Npc[m_nNpcIdx].m_CurrentLightResist = pInfo->m_nLightingResist;
  124. Npc[m_nNpcIdx].m_CurrentLightResistMax = pInfo->m_nLightingResistMax;
  125. Npc[m_nNpcIdx].m_CurrentPoisonResist = pInfo->m_nPoisonResist;
  126. Npc[m_nNpcIdx].m_CurrentPoisonResistMax = pInfo->m_nPoisonResistMax;
  127. Npc[m_nNpcIdx].m_CurrentPhysicsResist = pInfo->m_nPhycicsResist;
  128. Npc[m_nNpcIdx].m_CurrentPhysicsResistMax = pInfo->m_nPhycicsResistMax;
  129. #ifdef _SERVER
  130. if (pInfo->m_dwSkill5ID && pInfo->m_szSkill5Level[0])
  131. {
  132. Npc[m_nNpcIdx].m_SkillList.SetNpcSkill(
  133. defNPC_GOLD_SKILL_NO,
  134. pInfo->m_dwSkill5ID,
  135. KNpcTemplate::GetNpcLevelDataFromScript(g_pNpcLevelScript, "Level5", Npc[m_nNpcIdx].m_Level, pInfo->m_szSkill5Level));
  136. Npc[m_nNpcIdx].SetAuraSkill(pInfo->m_dwSkill5ID);
  137. }
  138. #endif
  139. // 按比例放大
  140. Npc[m_nNpcIdx].m_Experience *= pInfo->m_nExp;
  141. Npc[m_nNpcIdx].m_CurrentLifeMax *= pInfo->m_nLife;
  142. Npc[m_nNpcIdx].m_CurrentLifeReplenish *= pInfo->m_nLifeReplenish;
  143. Npc[m_nNpcIdx].m_CurrentAttackRating *= pInfo->m_nAttackRating;
  144. Npc[m_nNpcIdx].m_CurrentDefend *= pInfo->m_nDefense;
  145. Npc[m_nNpcIdx].m_PhysicsDamage.nValue[0] *= pInfo->m_nMinDamage;
  146. Npc[m_nNpcIdx].m_PhysicsDamage.nValue[2] *= pInfo->m_nMaxDamage;
  147. // 加点数
  148. Npc[m_nNpcIdx].m_CurrentTreasure += pInfo->m_nTreasure;
  149. Npc[m_nNpcIdx].m_CurrentWalkSpeed += pInfo->m_nWalkSpeed;
  150. Npc[m_nNpcIdx].m_CurrentRunSpeed += pInfo->m_nRunSpeed;
  151. Npc[m_nNpcIdx].m_CurrentAttackSpeed += pInfo->m_nAttackSpeed;
  152. Npc[m_nNpcIdx].m_CurrentCastSpeed += pInfo->m_nCastSpeed;
  153. Npc[m_nNpcIdx].m_CurrentLife = Npc[m_nNpcIdx].m_CurrentLifeMax;
  154. #ifdef _SERVER
  155. // 向周围九屏广播
  156. NPC_GOLD_CHANGE_SYNC sSync;
  157. sSync.ProtocolType = s2c_npcgoldchange;
  158. sSync.m_dwNpcID = Npc[this->m_nNpcIdx].m_dwID;
  159. sSync.m_wGoldFlag = this->GetGoldType();
  160. Npc[m_nNpcIdx].SendDataToNearRegion((LPVOID)&sSync, sizeof(NPC_GOLD_CHANGE_SYNC));
  161. #endif
  162. }
  163. //---------------------------------------------------------------------------
  164. // 功能:获得当前黄金类型,0 非黄金怪
  165. //---------------------------------------------------------------------------
  166. int KNpcGold::GetGoldType()
  167. {
  168. if (!m_nIsGold || !m_nIsGolding)
  169. return 0;
  170. return m_nGoldType + 1;
  171. }
  172. #ifndef _SERVER
  173. void KNpcGold::SetGoldCurrentType(int nType)
  174. {
  175. if (nType <= 0)
  176. {
  177. m_nIsGold = 0;
  178. m_nIsGolding = 0;
  179. return;
  180. }
  181. m_nIsGold = 1;
  182. m_nIsGolding = 1;
  183. m_nGoldType = nType - 1;
  184. }
  185. #endif
  186. #ifndef _SERVER
  187. void KNpcGold::ClientClearState()
  188. {
  189. m_nIsGold = 0;
  190. m_nIsGolding = 0;
  191. }
  192. #endif
  193. KNpcGoldTemplate::KNpcGoldTemplate()
  194. {
  195. memset(this->m_sInfo, 0, sizeof(this->m_sInfo));
  196. this->m_nEffectTypeNum = 0;
  197. }
  198. BOOL KNpcGoldTemplate::Init()
  199. {
  200. KTabFile cFile;
  201. // g_SetFilePath("\");
  202. if (!cFile.Load(NPC_GOLD_TEMPLATE_FILE))
  203. return FALSE;
  204. char szTemp[80];
  205. int i;
  206. for (i = 0; i < defMAX_NPC_GOLD_TYEP; i++)
  207. {
  208. cFile.GetString(i + 2, 1, "", szTemp, sizeof(szTemp));
  209. if (szTemp[0] == 0)
  210. break;
  211. cFile.GetInteger(i + 2,  2, 1, &m_sInfo[i].m_nExp);
  212. cFile.GetInteger(i + 2,  3, 1, &m_sInfo[i].m_nLife);
  213. cFile.GetInteger(i + 2,  4, 1, &m_sInfo[i].m_nLifeReplenish);
  214. cFile.GetInteger(i + 2,  5, 1, &m_sInfo[i].m_nAttackRating);
  215. cFile.GetInteger(i + 2,  6, 1, &m_sInfo[i].m_nDefense);
  216. cFile.GetInteger(i + 2,  7, 1, &m_sInfo[i].m_nMinDamage);
  217. cFile.GetInteger(i + 2,  8, 1, &m_sInfo[i].m_nMaxDamage);
  218. cFile.GetInteger(i + 2,  9, 0, &m_sInfo[i].m_nTreasure);
  219. cFile.GetInteger(i + 2, 10, 0, &m_sInfo[i].m_nWalkSpeed);
  220. cFile.GetInteger(i + 2, 11, 0, &m_sInfo[i].m_nRunSpeed);
  221. cFile.GetInteger(i + 2, 12, 0, &m_sInfo[i].m_nAttackSpeed);
  222. cFile.GetInteger(i + 2, 13, 0, &m_sInfo[i].m_nCastSpeed);
  223. cFile.GetString(i + 2, 14, "", szTemp, sizeof(szTemp));
  224. m_sInfo[i].m_dwSkill5ID = KNpcTemplate::SkillString2Id(szTemp);
  225. cFile.GetString(i + 2, 15, "", m_sInfo[i].m_szSkill5Level, sizeof(m_sInfo[i].m_szSkill5Level));
  226. cFile.GetInteger(i + 2, 16, 0, &m_sInfo[i].m_nFireResist);
  227. cFile.GetInteger(i + 2, 17, 0, &m_sInfo[i].m_nFireResistMax);
  228. cFile.GetInteger(i + 2, 18, 0, &m_sInfo[i].m_nColdResist);
  229. cFile.GetInteger(i + 2, 19, 0, &m_sInfo[i].m_nColdResistMax);
  230. cFile.GetInteger(i + 2, 20, 0, &m_sInfo[i].m_nLightingResist);
  231. cFile.GetInteger(i + 2, 21, 0, &m_sInfo[i].m_nLightingResistMax);
  232. cFile.GetInteger(i + 2, 22, 0, &m_sInfo[i].m_nPoisonResist);
  233. cFile.GetInteger(i + 2, 23, 0, &m_sInfo[i].m_nPoisonResistMax);
  234. cFile.GetInteger(i + 2, 24, 0, &m_sInfo[i].m_nPhycicsResist);
  235. cFile.GetInteger(i + 2, 25, 0, &m_sInfo[i].m_nPhycicsResistMax);
  236. }
  237. this->m_nEffectTypeNum = i;
  238. return TRUE;
  239. }