CombatHeroInfo.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Core.Language;
  4. using Core.Utility;
  5. using Excel2Json;
  6. using Fort23.UTool;
  7. using GameLogic.Combat.CombatTool;
  8. using GameLogic.Hero;
  9. using GameLogic.Player;
  10. using UnityEngine;
  11. using UnityEngine.Serialization;
  12. using Utility;
  13. [System.Serializable]
  14. public class CombatHeroInfo
  15. {
  16. public enum AttributeType
  17. {
  18. Hp,
  19. Att,
  20. Def,
  21. }
  22. public int modelID;
  23. public EncryptionLong hp = new EncryptionLong();
  24. public EncryptionLong defense = new EncryptionLong();
  25. public EncryptionLong attack = new EncryptionLong();
  26. protected Map<HeroAttributeType, float> attributeValue = new Map<HeroAttributeType, float>();
  27. // public long
  28. public EncryptionFloat attSpeed
  29. {
  30. get { return _attSpeed; }
  31. }
  32. public EncryptionInt level;
  33. public EncryptionInt exp = new EncryptionInt();
  34. public HeroModelConfig modelConfig;
  35. public HeroPowerUpConfig powerUpConfig;
  36. public MonsterPowerUpConfig MonsterPowerUpConfig;
  37. public EncryptionFloat _attSpeed;
  38. /// <summary>
  39. /// 功法强度的加成 %
  40. /// </summary>
  41. public float gongFaStrength;
  42. /// <summary>
  43. /// 护盾
  44. /// </summary>
  45. public EncryptionLong Shield;
  46. /// <summary>
  47. /// 神识
  48. /// </summary>
  49. public EncryptionLong shenshi;
  50. /// <summary>
  51. /// 添加的攻击速度比例%
  52. /// </summary>
  53. public float addAttSpeed_bl;
  54. /// <summary>
  55. /// 金
  56. /// </summary>
  57. public float Metal = 100;
  58. /// <summary>
  59. /// 木
  60. /// </summary>
  61. public float Wood = 100;
  62. /// <summary>
  63. /// 水
  64. /// </summary>
  65. public float Water = 100;
  66. /// <summary>
  67. /// 火
  68. /// </summary>
  69. public float Fire = 100;
  70. /// <summary>
  71. /// 土
  72. /// </summary>
  73. public float Earth = 100;
  74. /// <summary>
  75. /// 金
  76. /// </summary>
  77. public float Metal_Injury;
  78. /// <summary>
  79. /// 木
  80. /// </summary>
  81. public float Wood_Injury;
  82. /// <summary>
  83. /// 水
  84. /// </summary>
  85. public float Water_Injury;
  86. /// <summary>
  87. /// 火
  88. /// </summary>
  89. public float Fire_Injury;
  90. /// <summary>
  91. /// 土
  92. /// </summary>
  93. public float Earth_Injury;
  94. /// <summary>
  95. /// 火精通
  96. /// </summary>
  97. public float Fire_Proficient;
  98. /// <summary>
  99. /// 土精通
  100. /// </summary>
  101. public float Earth_Proficient;
  102. /// <summary>
  103. /// 水精通
  104. /// </summary>
  105. public float Water_Proficient;
  106. /// <summary>
  107. /// 毒精通
  108. /// </summary>
  109. public float Wood_Proficient;
  110. /// <summary>
  111. /// 流行精通
  112. /// </summary>
  113. public float Metal_Proficient;
  114. /// <summary>
  115. /// 异常伤害增加
  116. /// </summary>
  117. public float abnormalHarmAdd;
  118. /// <summary>
  119. /// 金伤害增加
  120. /// </summary>
  121. public float Metal_HarmAdd;
  122. /// <summary>
  123. /// 火伤害增加
  124. /// </summary>
  125. public float Fire_HarmAdd;
  126. /// <summary>
  127. /// 土伤害增加
  128. /// </summary>
  129. public float Earth_HarmAdd;
  130. /// <summary>
  131. /// 水伤害增加
  132. /// </summary>
  133. public float Water_HarmAdd;
  134. /// <summary>
  135. /// 木伤害增加
  136. /// </summary>
  137. public float Wood_HarmAdd;
  138. /// <summary>
  139. /// 最后伤害减少
  140. /// </summary>
  141. public float finallyHarmReduce;
  142. /// <summary>
  143. /// 最终伤害增加 buff伤害除外
  144. /// </summary>
  145. public float finallyHarmAdd;
  146. /// <summary>
  147. /// 1=英雄 2=小怪 3=精英怪 4=boss
  148. /// </summary>
  149. public int heroType;
  150. public string modelName;
  151. public bool isMonster;
  152. public int k;
  153. // public int[] skillId;
  154. // public List<SkillConfig> skillConfigs;
  155. /// <summary>
  156. /// 所有已解锁技能的ID
  157. /// </summary>
  158. public List<SkillInfo> unLockSkills = new List<SkillInfo>();
  159. public bool isGpu;
  160. public string heroName;
  161. public List<FaBaoInfo> MagicWeaponID = new List<FaBaoInfo>();
  162. /// <summary>
  163. /// 大道修炼ID
  164. /// </summary>
  165. public int TaoismSkillId;
  166. public float GetAttSpeed
  167. {
  168. get
  169. {
  170. float speed = CombatCalculateTool.Instance.GetVlaueRatioForFloat(attSpeed.Value,
  171. addAttSpeed_bl + 100);
  172. if (speed < 0)
  173. {
  174. speed = 0.01f;
  175. }
  176. return speed;
  177. }
  178. }
  179. public float GetAnimationSpeed
  180. {
  181. get { return GetAttSpeed / _attSpeed.Value; }
  182. }
  183. public CombatHeroInfo()
  184. {
  185. }
  186. protected Map<AttributeType, float> _AttributeCacheValue = new Map<AttributeType, float>();
  187. /// <summary>
  188. /// 获取五行灵根属性
  189. /// </summary>
  190. /// <param name="wuXingType"></param>
  191. /// <returns></returns>
  192. public float GetWuXingShuXing(WuXingType wuXingType)
  193. {
  194. switch (wuXingType)
  195. {
  196. case WuXingType.Gold:
  197. float Metal_v = Metal - Metal_Injury;
  198. if (Metal_v < 0)
  199. {
  200. Metal_v = 0;
  201. }
  202. return Metal_v;
  203. break;
  204. case WuXingType.Wood:
  205. float Wood_v = Wood - Wood_Injury;
  206. if (Wood_v < 0)
  207. {
  208. Wood_v = 0;
  209. }
  210. return Wood_v;
  211. break;
  212. case WuXingType.Water:
  213. float Water_v = Water - Water_Injury;
  214. if (Water_v < 0)
  215. {
  216. Water_v = 0;
  217. }
  218. return Water_v;
  219. break;
  220. case WuXingType.Fire:
  221. float Fire_v = Fire - Fire_Injury;
  222. if (Fire_v < 0)
  223. {
  224. Fire_v = 0;
  225. }
  226. return Fire_v;
  227. break;
  228. case WuXingType.Earth:
  229. float Earth_v = Earth - Earth_Injury;
  230. if (Earth_v < 0)
  231. {
  232. Earth_v = 0;
  233. }
  234. return Earth_v;
  235. break;
  236. default:
  237. return 100;
  238. return 0;
  239. }
  240. }
  241. protected void CalBasicAttribute()
  242. {
  243. _AttributeCacheValue.Clear();
  244. modelID = modelConfig.ID;
  245. if (isMonster)
  246. {
  247. unLockSkills.Clear();
  248. hp = (EncryptionLong)(modelConfig.hp * MonsterPowerUpConfig.HPFactor);
  249. defense = (EncryptionLong)(modelConfig.def * MonsterPowerUpConfig.DEFFactor);
  250. attack = (EncryptionLong)(modelConfig.attack * MonsterPowerUpConfig.ATKFactor);
  251. k = MonsterPowerUpConfig.defK;
  252. Metal = modelConfig.Linggen[0] * MonsterPowerUpConfig.LinggenUp / 100;
  253. Water = modelConfig.Linggen[1] * MonsterPowerUpConfig.LinggenUp / 100;
  254. Wood = modelConfig.Linggen[2] * MonsterPowerUpConfig.LinggenUp / 100;
  255. Fire = modelConfig.Linggen[3] * MonsterPowerUpConfig.LinggenUp / 100;
  256. Earth = modelConfig.Linggen[4] * MonsterPowerUpConfig.LinggenUp / 100;
  257. Shield = (EncryptionLong)(modelConfig.shield * MonsterPowerUpConfig.HudunFactor);
  258. SetSkillAttSpeed(modelConfig.speed_atk);
  259. if (modelConfig.skillID != null)
  260. {
  261. for (int i = 0; i < modelConfig.skillID.Length; i++)
  262. {
  263. int id = modelConfig.skillID[i];
  264. if (id <= 0)
  265. {
  266. continue;
  267. }
  268. int startLevel = modelConfig.skillActiveLv[i];
  269. if (startLevel > 0 && level < startLevel)
  270. {
  271. continue;
  272. }
  273. SkillInfo skillInfo =
  274. new SkillInfo(id, MonsterPowerUpConfig.GongfaLv, MonsterPowerUpConfig.GongfaStar);
  275. skillInfo.index = i;
  276. unLockSkills.Add(skillInfo);
  277. }
  278. }
  279. if (modelConfig.fa_bao_id != null)
  280. {
  281. for (int i = 0; i < modelConfig.fa_bao_id.Length; i++)
  282. {
  283. int faBaoId = modelConfig.fa_bao_id[i];
  284. int startLevel = modelConfig.fabaoActiveLv[i];
  285. if (startLevel > 0 && level < startLevel)
  286. {
  287. continue;
  288. }
  289. if (faBaoId > 0)
  290. {
  291. FaBaoInfo faBaoInfo = new FaBaoInfo(faBaoId, MonsterPowerUpConfig.FabaoLv,
  292. MonsterPowerUpConfig.FabaoStar);
  293. MagicWeaponID.Add(faBaoInfo);
  294. }
  295. }
  296. }
  297. }
  298. else
  299. {
  300. hp = (EncryptionLong)(modelConfig.hp * powerUpConfig.HPFactor);
  301. defense = (EncryptionLong)(modelConfig.def * powerUpConfig.DEFFactor);
  302. attack = (EncryptionLong)(modelConfig.attack * powerUpConfig.ATKFactor);
  303. Shield = (EncryptionLong)(modelConfig.shield * powerUpConfig.HudunFactor);
  304. // shenshi = (EncryptionLong)(modelConfig.shenshi * powerUpConfig.ShenshiFactor);
  305. k = powerUpConfig.defK;
  306. }
  307. for (_AttributeCacheValue.Begin(); _AttributeCacheValue.Next();)
  308. {
  309. switch (_AttributeCacheValue.Key)
  310. {
  311. case AttributeType.Hp:
  312. hp += CombatCalculateTool.Instance.GetVlaueRatioForLong(hp.Value, _AttributeCacheValue.Value);
  313. break;
  314. case AttributeType.Att:
  315. attack += CombatCalculateTool.Instance.GetVlaueRatioForLong(attack.Value,
  316. _AttributeCacheValue.Value);
  317. break;
  318. case AttributeType.Def:
  319. defense += CombatCalculateTool.Instance.GetVlaueRatioForLong(defense.Value,
  320. _AttributeCacheValue.Value);
  321. break;
  322. }
  323. }
  324. if (!isMonster)
  325. {
  326. for (int i = 0; i < MagicWeaponID.Count; i++)
  327. {
  328. FaBaoInfo faBaoInfo = MagicWeaponID[i];
  329. foreach (var VARIABLE in faBaoInfo.attriButedIC)
  330. {
  331. switch (VARIABLE.Key)
  332. {
  333. case 1:
  334. ComputeHeroAttributeType((int)HeroAttributeType.HP, VARIABLE.Value);
  335. // hp += VARIABLE.Value;
  336. break;
  337. case 2:
  338. ComputeHeroAttributeType((int)HeroAttributeType.DEF, VARIABLE.Value);
  339. // defense += VARIABLE.Value;
  340. break;
  341. case 3:
  342. ComputeHeroAttributeType((int)HeroAttributeType.ATT, VARIABLE.Value);
  343. // attack += VARIABLE.Value;
  344. break;
  345. }
  346. }
  347. }
  348. if (isMonster)
  349. {
  350. AddAttributeValue();
  351. }
  352. }
  353. }
  354. public SkillConfig GetGroupSkillConfig(int idGroup)
  355. {
  356. if (unLockSkills == null)
  357. {
  358. return default;
  359. }
  360. for (int i = 0; i < unLockSkills.Count; i++)
  361. {
  362. // SkillConfig skillConfig = ConfigComponent.Instance.Get<SkillConfig>(unLockSkills[i]);
  363. if (unLockSkills[i].skillConfig.IDGroup == idGroup)
  364. {
  365. return unLockSkills[i].skillConfig;
  366. }
  367. }
  368. return default;
  369. }
  370. protected void CalAttribute()
  371. {
  372. CalBasicAttribute();
  373. // skillId = modelConfig.skillID;
  374. modelName = modelConfig.model;
  375. isGpu = modelConfig.isUseGpu;
  376. heroType = modelConfig.heroType;
  377. }
  378. public void SetSkillAttSpeed(float attSpeed)
  379. {
  380. _attSpeed = (EncryptionFloat)(1.0f / attSpeed);
  381. }
  382. protected void SetDataConfig(int modelID, int level)
  383. {
  384. modelConfig = ConfigComponent.Instance.Get<HeroModelConfig>(modelID);
  385. if (isMonster)
  386. {
  387. MonsterPowerUpConfig = ConfigComponent.Instance.Get<MonsterPowerUpConfig>(level);
  388. }
  389. else
  390. {
  391. powerUpConfig = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  392. }
  393. this.level = (EncryptionInt)level;
  394. heroName = LanguageManager.Instance.Text(modelConfig.name);
  395. }
  396. public void InitMonster(int modelID, int level)
  397. {
  398. isMonster = true;
  399. SetDataConfig(modelID, level);
  400. CalAttribute();
  401. }
  402. public CombatHeroInfo Copy()
  403. {
  404. CombatHeroInfo combatHeroInfo = (CombatHeroInfo)MemberwiseClone();
  405. return combatHeroInfo;
  406. }
  407. protected void ComputeHeroAttributeType(int shuxingID, float value)
  408. {
  409. HeroAttributeType heroAttributeType = (HeroAttributeType)shuxingID;
  410. if (attributeValue.TryGetValue(heroAttributeType, out float oldValue))
  411. {
  412. attributeValue[heroAttributeType] = oldValue + value;
  413. }
  414. else
  415. {
  416. attributeValue.Add(heroAttributeType, value);
  417. }
  418. // attributeValue.Add((HeroAttributeType)shuxingID,);
  419. }
  420. protected void AddAttributeValue()
  421. {
  422. for (attributeValue.Begin(); attributeValue.Next();)
  423. {
  424. HeroAttributeType heroAttributeType = attributeValue.Key;
  425. float value = attributeValue.Value;
  426. switch (heroAttributeType)
  427. {
  428. case HeroAttributeType.HP:
  429. hp.Value += (int)value;
  430. break;
  431. case HeroAttributeType.ATT:
  432. attack.Value += (int)value;
  433. break;
  434. case HeroAttributeType.DEF:
  435. defense.Value += (int)value;
  436. break;
  437. case HeroAttributeType.Gold:
  438. Metal += value;
  439. break;
  440. case HeroAttributeType.Wood:
  441. Wood += value;
  442. break;
  443. case HeroAttributeType.Fire:
  444. Fire += value;
  445. break;
  446. case HeroAttributeType.Water:
  447. Water += value;
  448. break;
  449. case HeroAttributeType.Earth:
  450. Earth += value;
  451. break;
  452. case HeroAttributeType.Shields:
  453. Shield.Value += (int)value;
  454. break;
  455. }
  456. }
  457. for (attributeValue.Begin(); attributeValue.Next();)
  458. {
  459. HeroAttributeType heroAttributeType = attributeValue.Key;
  460. float value = attributeValue.Value;
  461. switch (heroAttributeType)
  462. {
  463. case HeroAttributeType.HP_BL:
  464. hp.Value += (long)(hp.Value * (value / 100f));
  465. break;
  466. case HeroAttributeType.ATT_BL:
  467. attack.Value += (long)(attack.Value * (value / 100f));
  468. break;
  469. case HeroAttributeType.DEF_BL:
  470. defense.Value += (long)(defense.Value * (value / 100f));
  471. break;
  472. case HeroAttributeType.ShengShi_BL:
  473. shenshi.Value += (long)(shenshi.Value * (value / 100f));
  474. break;
  475. }
  476. }
  477. attributeValue.Clear();
  478. }
  479. }