CombatHeroInfo.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. public EncryptionFloat attSpeed
  27. {
  28. get { return _attSpeed; }
  29. }
  30. public EncryptionInt level;
  31. public EncryptionInt exp = new EncryptionInt();
  32. public HeroModelConfig modelConfig;
  33. public HeroPowerUpConfig powerUpConfig;
  34. public MonsterPowerUpConfig MonsterPowerUpConfig;
  35. public EncryptionFloat _attSpeed;
  36. /// <summary>
  37. /// 功法强度的加成 %
  38. /// </summary>
  39. public float gongFaStrength;
  40. /// <summary>
  41. /// 护盾
  42. /// </summary>
  43. public EncryptionLong Shield;
  44. /// <summary>
  45. /// 神识
  46. /// </summary>
  47. public EncryptionLong shenshi;
  48. /// <summary>
  49. /// 添加的攻击速度比例%
  50. /// </summary>
  51. public float addAttSpeed_bl;
  52. /// <summary>
  53. /// 金
  54. /// </summary>
  55. public float Metal = 100;
  56. /// <summary>
  57. /// 木
  58. /// </summary>
  59. public float Wood = 100;
  60. /// <summary>
  61. /// 水
  62. /// </summary>
  63. public float Water = 100;
  64. /// <summary>
  65. /// 火
  66. /// </summary>
  67. public float Fire = 100;
  68. /// <summary>
  69. /// 土
  70. /// </summary>
  71. public float Earth = 100;
  72. /// <summary>
  73. /// 金
  74. /// </summary>
  75. public float Metal_Injury;
  76. /// <summary>
  77. /// 木
  78. /// </summary>
  79. public float Wood_Injury;
  80. /// <summary>
  81. /// 水
  82. /// </summary>
  83. public float Water_Injury;
  84. /// <summary>
  85. /// 火
  86. /// </summary>
  87. public float Fire_Injury;
  88. /// <summary>
  89. /// 土
  90. /// </summary>
  91. public float Earth_Injury;
  92. /// <summary>
  93. /// 1=英雄 2=小怪 3=精英怪 4=boss
  94. /// </summary>
  95. public int heroType;
  96. public string modelName;
  97. public bool isMonster;
  98. public int k;
  99. // public int[] skillId;
  100. // public List<SkillConfig> skillConfigs;
  101. /// <summary>
  102. /// 所有已解锁技能的ID
  103. /// </summary>
  104. public List<SkillInfo> unLockSkills = new List<SkillInfo>();
  105. public bool isGpu;
  106. public string heroName;
  107. public List<FaBaoInfo> MagicWeaponID = new List<FaBaoInfo>();
  108. /// <summary>
  109. /// 大道修炼ID
  110. /// </summary>
  111. public int TaoismSkillId;
  112. public float GetAttSpeed
  113. {
  114. get
  115. {
  116. float speed = CombatCalculateTool.Instance.GetVlaueRatioForFloat(attSpeed.Value,
  117. addAttSpeed_bl + 100);
  118. if (speed < 0)
  119. {
  120. speed = 0.01f;
  121. }
  122. return speed;
  123. }
  124. }
  125. public float GetAnimationSpeed
  126. {
  127. get { return GetAttSpeed / _attSpeed.Value; }
  128. }
  129. public CombatHeroInfo()
  130. {
  131. }
  132. protected Map<AttributeType, float> _AttributeCacheValue = new Map<AttributeType, float>();
  133. public void AddAttributeValueToCache(AttributeType attributeType, float value)
  134. {
  135. if (_AttributeCacheValue.TryGetValue(attributeType, out float v))
  136. {
  137. value += v;
  138. }
  139. _AttributeCacheValue[attributeType] = value;
  140. }
  141. /// <summary>
  142. /// 获取五行灵根属性
  143. /// </summary>
  144. /// <param name="wuXingType"></param>
  145. /// <returns></returns>
  146. public float GetWuXingShuXing(WuXingType wuXingType)
  147. {
  148. switch (wuXingType)
  149. {
  150. case WuXingType.Gold:
  151. float Metal_v = Metal - Metal_Injury;
  152. if (Metal_v < 0)
  153. {
  154. Metal_v = 0;
  155. }
  156. return Metal_v;
  157. break;
  158. case WuXingType.Wood:
  159. float Wood_v = Wood - Wood_Injury;
  160. if (Wood_v < 0)
  161. {
  162. Wood_v = 0;
  163. }
  164. return Wood_v;
  165. break;
  166. case WuXingType.Water:
  167. float Water_v = Water - Water_Injury;
  168. if (Water_v < 0)
  169. {
  170. Water_v = 0;
  171. }
  172. return Water_v;
  173. break;
  174. case WuXingType.Fire:
  175. float Fire_v = Fire - Fire_Injury;
  176. if (Fire_v < 0)
  177. {
  178. Fire_v = 0;
  179. }
  180. return Fire_v;
  181. break;
  182. case WuXingType.Earth:
  183. float Earth_v = Earth - Earth_Injury;
  184. if (Earth_v < 0)
  185. {
  186. Earth_v = 0;
  187. }
  188. return Earth_v;
  189. break;
  190. default:
  191. return 0;
  192. }
  193. }
  194. protected void CalBasicAttribute()
  195. {
  196. _AttributeCacheValue.Clear();
  197. if (isMonster)
  198. {
  199. unLockSkills.Clear();
  200. hp = (EncryptionLong)(modelConfig.hp * MonsterPowerUpConfig.HPFactor);
  201. defense = (EncryptionLong)(modelConfig.def * MonsterPowerUpConfig.DEFFactor);
  202. attack = (EncryptionLong)(modelConfig.attack * MonsterPowerUpConfig.ATKFactor);
  203. k = MonsterPowerUpConfig.defK;
  204. if (modelConfig.skillID != null)
  205. {
  206. for (int i = 0; i < modelConfig.skillID.Length; i++)
  207. {
  208. int id = modelConfig.skillID[i];
  209. if (id <= 0)
  210. {
  211. continue;
  212. }
  213. int start = MonsterPowerUpConfig.GongfaStar;
  214. int skillid = id * 10 + start;
  215. while (start >= 0)
  216. {
  217. SkillConfig skillConfig = ConfigComponent.Instance.Get<SkillConfig>(skillid);
  218. if (skillConfig.ID > 0)
  219. {
  220. break;
  221. }
  222. start--;
  223. skillid = id * 10 + start;
  224. }
  225. SkillInfo skillInfo = new SkillInfo(skillid, MonsterPowerUpConfig.GongfaLv);
  226. skillInfo.index = i;
  227. unLockSkills.Add(skillInfo);
  228. }
  229. }
  230. if (modelConfig.fa_bao_id != null)
  231. {
  232. for (int i = 0; i < modelConfig.fa_bao_id.Length; i++)
  233. {
  234. int faBaoId = modelConfig.fa_bao_id[i];
  235. if (faBaoId > 0)
  236. {
  237. FaBaoInfo faBaoInfo = new FaBaoInfo(faBaoId, MonsterPowerUpConfig.FabaoLv,
  238. MonsterPowerUpConfig.FabaoStar);
  239. MagicWeaponID.Add(faBaoInfo);
  240. }
  241. }
  242. }
  243. }
  244. else
  245. {
  246. hp = (EncryptionLong)(modelConfig.hp * powerUpConfig.HPFactor);
  247. defense = (EncryptionLong)(modelConfig.def * powerUpConfig.DEFFactor);
  248. attack = (EncryptionLong)(modelConfig.attack * powerUpConfig.ATKFactor);
  249. Shield = (EncryptionLong)(modelConfig.shield * powerUpConfig.HudunFactor);
  250. // shenshi = (EncryptionLong)(modelConfig.shenshi * powerUpConfig.ShenshiFactor);
  251. k = powerUpConfig.defK;
  252. }
  253. for (_AttributeCacheValue.Begin(); _AttributeCacheValue.Next();)
  254. {
  255. switch (_AttributeCacheValue.Key)
  256. {
  257. case AttributeType.Hp:
  258. hp += CombatCalculateTool.Instance.GetVlaueRatioForLong(hp.Value, _AttributeCacheValue.Value);
  259. break;
  260. case AttributeType.Att:
  261. attack += CombatCalculateTool.Instance.GetVlaueRatioForLong(attack.Value,
  262. _AttributeCacheValue.Value);
  263. break;
  264. case AttributeType.Def:
  265. defense += CombatCalculateTool.Instance.GetVlaueRatioForLong(defense.Value,
  266. _AttributeCacheValue.Value);
  267. break;
  268. }
  269. }
  270. }
  271. public SkillConfig GetGroupSkillConfig(int idGroup)
  272. {
  273. if (unLockSkills == null)
  274. {
  275. return default;
  276. }
  277. for (int i = 0; i < unLockSkills.Count; i++)
  278. {
  279. // SkillConfig skillConfig = ConfigComponent.Instance.Get<SkillConfig>(unLockSkills[i]);
  280. if (unLockSkills[i].skillConfig.IDGroup == idGroup)
  281. {
  282. return unLockSkills[i].skillConfig;
  283. }
  284. }
  285. return default;
  286. }
  287. protected void CalAttribute()
  288. {
  289. CalBasicAttribute();
  290. _attSpeed = (EncryptionFloat)(1.0f / modelConfig.speed_atk);
  291. // skillId = modelConfig.skillID;
  292. modelName = modelConfig.model;
  293. isGpu = modelConfig.isUseGpu;
  294. heroType = modelConfig.heroType;
  295. }
  296. protected void AddSkillAttribute(SkillConfig skillConfig)
  297. {
  298. if (skillConfig.addPropertyType == null)
  299. {
  300. return;
  301. }
  302. for (int i = 0; i < skillConfig.addPropertyType.Length; i++)
  303. {
  304. int propertyType = skillConfig.addPropertyType[i];
  305. float value = skillConfig.addPropertyValue[i];
  306. switch (propertyType)
  307. {
  308. case 101:
  309. AddAttributeValueToCache(AttributeType.Hp, value);
  310. break;
  311. case 102:
  312. AddAttributeValueToCache(AttributeType.Att, value);
  313. break;
  314. case 103:
  315. AddAttributeValueToCache(AttributeType.Def, value);
  316. break;
  317. }
  318. }
  319. }
  320. protected void SetDataConfig(int modelID, int level)
  321. {
  322. modelConfig = ConfigComponent.Instance.Get<HeroModelConfig>(modelID);
  323. if (isMonster)
  324. {
  325. MonsterPowerUpConfig = ConfigComponent.Instance.Get<MonsterPowerUpConfig>(level);
  326. }
  327. else
  328. {
  329. powerUpConfig = ConfigComponent.Instance.Get<HeroPowerUpConfig>(level);
  330. }
  331. this.level = (EncryptionInt)level;
  332. heroName = LanguageManager.Instance.Text(modelConfig.name);
  333. }
  334. public void InitMonster(int modelID, int level)
  335. {
  336. isMonster = true;
  337. SetDataConfig(modelID, level);
  338. CalAttribute();
  339. }
  340. public CombatHeroInfo Copy()
  341. {
  342. CombatHeroInfo combatHeroInfo = (CombatHeroInfo)MemberwiseClone();
  343. return combatHeroInfo;
  344. }
  345. }